Re: Love to get some feedback on my first python app!!!
I have just committed a new main.py file on github. I added alot more comments and slimmed down the getinfo() function. -- https://mail.python.org/mailman/listinfo/python-list
one problem in cx_Freeze4.3.3 for Python3.4
#torrent.py - import re import urllib.request import urllib.parse urltemp = 'https://btdigg.org/search?info_hash=&q=' urlinput = urllib.parse.quote(input('Please input keywords:')) url = urltemp + urlinput print('Searching'+'\n'+url) content = urllib.parse.unquote(urllib.request.urlopen(url).read().decode('utf-8')) recon = re.findall(r'href="(magnet:.+?)"',content) print('Order address'+'\n'+str(recon)) a=[] for temp in recon: b = re.sub(';','&',temp) a.append(b) print('Right address'+'\n'+str(a)) print('Address has been updated') file = open('torrent.txt','w') for temp2 in a: file.write(temp2+'\n') file.close() -- I use cx_Freeze to project it into '.exe',but when I turn on 'torrent.exe' it tips that: AttributeError: 'module object has no attribute '_fix_up_module' -- cx_Freeze log: --- creating directory dist copying D:\Program Files\Python\lib\site-packages\cx_freeze-4.3.3-py3.4-win32.egg\cx_Freeze\bases\Console.exe -> dist\torrent.exe copying C:\Windows\SYSTEM32\python34.dll -> dist\python34.dll writing zip file dist\torrent.exe Name File m __main__ torrent.py m _bisect m _bootlocale m _bz2 D:\Program Files\Python\DLLs\_bz2.pyd m _codecs m _codecs_cn m _codecs_hk m _codecs_iso2022 m _codecs_jp m _codecs_kr m _codecs_tw m _collections m _collections_abc m _datetime m _dummy_thread m _functools m _hashlib D:\Program Files\Python\DLLs\_hashlib.pyd m _heapq m _imp m _io m _locale m _lzma D:\Program Files\Python\DLLs\_lzma.pyd m _md5 m _multibytecodec m _operator m _osx_support D:\Program Files\Python\lib\_osx_support.py m _random m _sha1 m _sha256 m _sha512 m _socket D:\Program Files\Python\DLLs\_socket.pyd m _sre m _ssl D:\Program Files\Python\DLLs\_ssl.pyd m _stat m _string m _strptime m _struct m _thread m _threading_local m _warnings m _weakref m _weakrefset m abc m argparse m array m atexit m base64 m binascii m bisectD:\Program Files\Python\lib\bisect.py m builtins m bz2 m calendar m codecs P collections m collections.abc m contextlib m copy m copyreg m cx_Freeze__init__ D:\Program Files\Python\lib\site-packages\cx_freeze-4.3.3-py3.4-win32.egg\cx_Freeze\initscripts\Console.py m datetime P distutils D:\Program Files\Python\lib\distutils\__init__.py m distutils.debug D:\Program Files\Python\lib\distutils\debug.py m distutils.errors D:\Program Files\Python\lib\distutils\errors.py m distutils.log D:\Program Files\Python\lib\distutils\log.py m distutils.spawn D:\Program Files\Python\lib\distutils\spawn.py m distutils.sysconfig D:\Program Files\Python\lib\distutils\sysconfig.py m distutils.text_file D:\Program Files\Python\lib\distutils\text_file.py m dummy_threading P email D:\Program Files\Python\lib\email\__init__.py m email._encoded_words D:\Program Files\Python\lib\email\_encoded_words.py m email._header_value_parser D:\Program Files\Python\lib\email\_header_value_parser.py m email._parseaddr D:\Program Files\Python\lib\email\_parseaddr.py m email._policybase D:\Program Files\Python\lib\email\_policybase.py m email.base64mime D:\Program Files\Python\lib\email\base64mime.py m email.charset D:\Program Files\Python\lib\email\charset.py m email.contentmanager D:\Program Files\Python\lib\email\contentmanager.py m email.encodersD:\Program Files\Python\lib\email\encoders.py m email.errors D:\Program Files\Python\lib\email\errors.py m email.feedparser D:\Program Files\Python\lib\email\feedparser.py m email.generator D:\Program Files\Py
Re: Love to get some feedback on my first python app!!!
On Sun, Sep 21, 2014 at 11:33 AM, Nicholas Cannon wrote: > Yeah this is exactly what I was looking for I know the comments are horrible > and I had no idea about the camelCase stuff. Should I use > ''' > Use this commenting on my functions or not. I think they are called > docStrings or something > ''' Yes, they're called docstrings (without the capital S - again, Python doesn't tend to work that way). You can find info and advice all over the web about how to write good, useful docstrings. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Saturday, September 20, 2014 9:17:27 PM UTC+8, Nicholas Cannon wrote: > I have created my first python program and I have learnt a lot about python > from this group and wanted some feedback. I am still improving it and trying > to tackle some performance and GUI stuff so keep that in mind. I don't think > it is the best program but is a good product of 3 months of python. > > > > link: https://github.com/nicodasiko/Article-Grab Yeah this is exactly what I was looking for I know the comments are horrible and I had no idea about the camelCase stuff. Should I use ''' Use this commenting on my functions or not. I think they are called docStrings or something ''' I have a free day today and I am going to fix up some GUI stuff and try and slim down the processing and amount of variables because it doesnt really run as fast. Thanks for the help Chris Angelico! -- https://mail.python.org/mailman/listinfo/python-list
Re: Pybuez Client sending messages to j2me Server
On Wednesday, May 6, 2009 11:38:16 AM UTC+3, CkurtM wrote: > I have a problem with recieving requests on j2me based bluetooth > server using RFCOMM. I can send messages from the j2me client to > python server, but cant receive from the python bluetooth client to > j2me server, it only connects but doesnt receive??.I can send copy of > code on request. > I'm using pybluez on python 2.6 > and standard javax.bluetooth for the mobile interface. Any help wud be > welcome. > Thanks in advance. Hi CkurtM, Can you please post your J2ME Client Code that connects to Python Server ? I actually -- https://mail.python.org/mailman/listinfo/python-list
Re: Class Inheritance from different module
Juan Christian wrote: > I have the following structure: > > Third-party API installed via pip: > steamapi / > app.py > consts.py > core.py > users.py > [...] > > My script: > test.py > > > In the API, the module users.py has a class 'SteamUser' and I want to > mimic it's usage on my code, like this: > > import steamapi > > [...] > > class User(Inheritance from API): > def __init__(self, ID): > steamapi.core.APIConnection(api_key = KEY) > super( " Inheritance SteamUser" (ID)) # creates the user using the API > > [...] > > So that in my code when I need to create a new user, I just call 'usr = > User("XXX")' instead of calling 'usr = > steamapi.user.SteamUser(76561197996416028)', is that possible? Yes, it doesn't matter in what module a baseclass is defined. Just go ahead and import it: # untested import steamapi.user class User(steamapi.user.User): def __init__(self, userid=None, userurl=None): super().__init__(userid, userurl) # code specific to you subclass > And of > course, I want to have access to all the class methods like 'name', > 'country_code', 'time_created', 'avatar', 'friends' and so on. That's the very idea of subclassing. > And finally, is that a good approach, pythonic? It depends ;) If you are planning only small adjustments it might be an option to write a few helper functions together with the original steamapi.user.User class and be done. > If not, what would be a good way? Generally speaking the Python community often favours duck-typing or composition over inheritance. I'm not prepared to go into a lengthy discussion over this -- if you are interested you have to try a search engine or rely on the usual suspects ;) -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 20/09/2014 15:58, Chris Angelico wrote: On Sat, Sep 20, 2014 at 11:16 PM, Nicholas Cannon wrote: You may also notice that the camelCase variable names you're using are in stark contrast to the rest of the language. It's normal to use lower_case_with_underscores instead. That may be the PEP 8 guideline but I don't regard it as normal, I find camelCase far easier to read. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Sat, Sep 20, 2014 at 11:16 PM, Nicholas Cannon wrote: > I have created my first python program and I have learnt a lot about python > from this group and wanted some feedback. I am still improving it and trying > to tackle some performance and GUI stuff so keep that in mind. I don't think > it is the best program but is a good product of 3 months of python. > > link: https://github.com/nicodasiko/Article-Grab Sure! But first, a couple of points that aren't specifically Python... Firstly, you're using Google Groups. Until someone gets inside Google and fixes up the code, it will make a mess of every post made through it. Please use something better... either subscribe to the mailing list and do everything through email, or access the newsgroup comp.lang.python via a better client, or something of the sort. Secondly, a note about verb tenses in English. You have this commit message on the (as of 20140921) latest commit: """Fixed some bugs and did some GUI changes""" And these comments in the code: #search API rawData = urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='+encodedQuery).read() #loads data from API into json jsonData = json.loads(rawData) #extracts the results from API searchResults = jsonData['responseData']['results'] The more normal way to write these would be in present tense, in a more imperative style: "Fix some bugs", "Load data", "Extract results". (Although these comments are actually quite redundant - all they do is tell you what the single next line of code does.) You may also notice that the camelCase variable names you're using are in stark contrast to the rest of the language. It's normal to use lower_case_with_underscores instead. Now, let's have a look at the code itself. query = queryVar.get() ... and further down ... global queryVar queryVar = StringVar() You don't need to say "global" at top level. Everything at top-level is global. However, I generally like to, as much as possible, define things higher in the file than their usages - so that as you read the file, the first reference to anything is the one that tells you what it is. That may not be practical here, but it's something to keep in mind. (This is why import statements generally go at the top of the file, for instance.) The language doesn't require it, but it does make the code easier for a human to read. links = [] for result in searchResults: #loops through the searchResults data to find the title and URL of the pages #and then add the links to the links list title = result['title'] link = result['url'] links.append(link) print links You're not doing anything with the title, so what you have here is a loop that builds up a list from empty, by repeated appends. That's a perfect job for a list comprehension: links = [result['url'] for result in searchResults] I'm not sure why you print the links to stdout there - is that some left-over debugging code? Although, the only thing you do with the list of URLs is to iterate over it, once. You could simply merge the two loops into one: for result in searchResults: url = result['url'] pageData = urllib.urlopen(url).read() ... etc ... Your text insertion is a little inconsistent: you put the URL and title at the cursor position, then the body at the end. Is that intentional? If so, that deserves a comment - which would be much more useful than the comments that say what we can read in the code already. textDisplay.insert(INSERT, 'This spider searches for information on your query and will display it here!') You haven't written a spider here :) You're just calling on Google's spider and showing some information. Similarly, the verb "CRAWL" on your button isn't really accurate - and isn't particularly helpful to the user either. I'd just word it in terms of how the user will value it, and say "Search" on the button. Keep it simple. queryWidgit = Entry(frame, textvariable=queryVar, fg='Blue', bd=5, width=50) It's normally "Widget", not "Widgit". Not significant, but you seem to have consistently used two i's, including in your comments. Well, you asked for feedback. That's normally going to consist of people pointing out where they think you did badly. But ultimately, this is all relatively minor, so if the program works, consider yourself to have broadly succeeded. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Class Inheritance from different module
Juan Christian wrote: [...] > In the API, the module users.py has a class 'SteamUser' and I want to > mimic it's usage on my code, like this: > > import steamapi > > [...] > > class User(Inheritance from API): What do you mean, "Inheritance from API"? You can't inherit from an API, only from classes. > def __init__(self, ID): > steamapi.core.APIConnection(api_key = KEY) > super( " Inheritance SteamUser" (ID)) # creates the user using the API > > [...] > > So that in my code when I need to create a new user, I just call 'usr = > User("XXX")' instead of calling 'usr = > steamapi.user.SteamUser(76561197996416028)', is that possible? I would do something like this: # untested def make_user(ID): steamapi.core.APIConnection(api_key = KEY) return steamapi.user.SteamUser(76561197996416028) usr = make_user("X") No need for inheritance. make_user returns an actual SteamUser instance, not some subclass. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Class Inheritance from different module
I have the following structure: Third-party API installed via pip: steamapi / app.py consts.py core.py users.py [...] My script: test.py In the API, the module users.py has a class 'SteamUser' and I want to mimic it's usage on my code, like this: import steamapi [...] class User(Inheritance from API): def __init__(self, ID): steamapi.core.APIConnection(api_key = KEY) super( " Inheritance SteamUser" (ID)) # creates the user using the API [...] So that in my code when I need to create a new user, I just call 'usr = User("XXX")' instead of calling 'usr = steamapi.user.SteamUser(76561197996416028)', is that possible? And of course, I want to have access to all the class methods like 'name', 'country_code', 'time_created', 'avatar', 'friends' and so on. And finally, is that a good approach, pythonic? If not, what would be a good way? -- https://mail.python.org/mailman/listinfo/python-list
Love to get some feedback on my first python app!!!
I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. link: https://github.com/nicodasiko/Article-Grab -- https://mail.python.org/mailman/listinfo/python-list
Re: pad binary string with a given byte value (python 3)
Nagy László Zsolt wrote: > >>> bytes/str.ljust() >>> >> def pad(b, n=16, c=b"\x0f"): >>> ... length = (len(b)+n-1)//n*n >>> ... return b.ljust(length, c) >> Thanks! > One more question. How do I create a single char binary string from a > number? E.g. > > >>> bytes([65]) > b'A' > > It seems to be wrong again. The bytes constructor requires a sequence, > and I don't like creating a list or a tuple just to convert it into a > binary string. Unfortunately I'm not aware of a function similar to chr() that creates bytes. -- https://mail.python.org/mailman/listinfo/python-list
Re: pad binary string with a given byte value (python 3)
bytes/str.ljust() def pad(b, n=16, c=b"\x0f"): ... length = (len(b)+n-1)//n*n ... return b.ljust(length, c) Thanks! One more question. How do I create a single char binary string from a number? E.g. >>> bytes([65]) b'A' It seems to be wrong again. The bytes constructor requires a sequence, and I don't like creating a list or a tuple just to convert it into a binary string. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- https://mail.python.org/mailman/listinfo/python-list
Re: pad binary string with a given byte value (python 3)
Nagy László Zsolt wrote: > I can figure out way for example this: > > >>> b'T'+bytearray([32]) > > but it just don't seem right to create a list, then convert it to a byte > array and then convert it to a binary string. What am I missing? By the way, you can repeat bytes (and strings) by multiplying: >>> b"\x01"*3 b'\x01\x01\x01' >>> b"ab"*3 b'ababab' -- https://mail.python.org/mailman/listinfo/python-list
Re: pad binary string with a given byte value (python 3)
bytes/str.ljust() def pad(b, n=16, c=b"\x0f"): ... length = (len(b)+n-1)//n*n ... return b.ljust(length, c) Thanks! -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- https://mail.python.org/mailman/listinfo/python-list
Re: pad binary string with a given byte value (python 3)
Nagy László Zsolt wrote: > >>> BS = 16 > >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) > >>> pad('L') > 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' > >>> pad(b'L') > Traceback (most recent call last): >File "", line 1, in >File "", line 1, in > TypeError: can't concat bytes to str > > How do I write this function so it can pad byte strings? chr(charcode) > creates a normal string, not a binary string. > > I can figure out way for example this: > > >>> b'T'+bytearray([32]) > > but it just don't seem right to create a list, then convert it to a byte > array and then convert it to a binary string. What am I missing? You don't need to write your own function, just use the relevant string and bytes methods. Use the ljust and rjust (left and right justify) methods: To add padding on the left, justify on the right, and vise versa: py> "Hello".ljust(20, "\x0f") 'Hello\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' py> "Hello".rjust(20, "\x0f") '\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0fHello' (The default fill character is space.) The same works for bytes, except you have to make sure your fill char is also a byte: py> b"Hello".rjust(20, b"\x0f") b'\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0fHello' py> b"Hello".ljust(20, b"\x0f") b'Hello\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: pad binary string with a given byte value (python 3)
Nagy László Zsolt wrote: > >>> BS = 16 > >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) > >>> pad('L') > 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' > >>> pad(b'L') > Traceback (most recent call last): >File "", line 1, in >File "", line 1, in > TypeError: can't concat bytes to str > > How do I write this function so it can pad byte strings? chr(charcode) > creates a normal string, not a binary string. > > I can figure out way for example this: > > >>> b'T'+bytearray([32]) > > but it just don't seem right to create a list, then convert it to a byte > array and then convert it to a binary string. What am I missing? bytes/str.ljust() >>> def pad(b, n=16, c=b"\x0f"): ... length = (len(b)+n-1)//n*n ... return b.ljust(length, c) ... >>> pad(b"abc", 5) b'abc\x0f\x0f' >>> pad(b"abcde", 5) b'abcde' >>> pad(b"abcdef", 5) b'abcdef\x0f\x0f\x0f\x0f' >>> pad("abcde", 5, "*") 'abcde' >>> pad("abcdef", 5, "*") 'abcdef' -- https://mail.python.org/mailman/listinfo/python-list
pad binary string with a given byte value (python 3)
>>> BS = 16 >>> pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) >>> pad('L') 'L\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f' >>> pad(b'L') Traceback (most recent call last): File "", line 1, in File "", line 1, in TypeError: can't concat bytes to str How do I write this function so it can pad byte strings? chr(charcode) creates a normal string, not a binary string. I can figure out way for example this: >>> b'T'+bytearray([32]) but it just don't seem right to create a list, then convert it to a byte array and then convert it to a binary string. What am I missing? -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- https://mail.python.org/mailman/listinfo/python-list