Re: md5 wrongness?
John Machin wrote: On Nov 24, 1:34 pm, Ron Johnson [EMAIL PROTECTED] wrote: Why do Python's md5 and GNU md5sum produce differing results? They don't differ. Try feeding them the same input: import md5 md5.new('snagglefrob').hexdigest() '9eb2459fcdd9f9b8a9fef7348bcac933' md5.new('snagglefrob\n').hexdigest() 'f842244d79af85b457811091319d85ff' Or, alternatively: $ echo -n snagglefrob | md5sum 9eb2459fcdd9f9b8a9fef7348bcac933 - -- Ayaz Ahmed Khan -- http://mail.python.org/mailman/listinfo/python-list
Re: Catching a segfault in a Python library
Donn Ingle wrote: Already done, the code within PIL is causing the crash. It gets ugly and out of my remit. It's a freetype/Pil thing and I simply want to a way to catch it when it happens. Since a segfault ends the process, I am asking about wrappers around code to catch a segfault. \d Wouldn't it be better to narrow down to what in your code is invoking PIL in a manner in which PIL exhibits such behaviour, and handle it within your code? Just a thought! -- Ayaz Ahmed Khan -- http://mail.python.org/mailman/listinfo/python-list
Re: the annoying, verbose self
braver wrote: Is there any trick to get rid of having to type the annoying, character-eating self. prefix everywhere in a class? Sometimes I avoid OO just not to deal with its verbosity. In fact, I try to use Ruby anywhere speed is not crucial especially for @ prefix is better- looking than self. I've never really understood why some people find that annoying to do. I make it a point to use, for example, the `this` operator when writing C++ code to avoid implicilty calling/accessing attributes of objects as much as possible. -- Ayaz Ahmed Khan -- http://mail.python.org/mailman/listinfo/python-list
Re: introspection and functions
James Stroud typed: py def doit(a, b, c, x=14): ... pass ... py doit.func_code.co_argcount 4 py doit.func_code.co_varnames ('a', 'b', 'c', 'x') py doit.func_defaults (14,) Neat. -- Ayaz Ahmed Khan I have not yet begun to byte! -- http://mail.python.org/mailman/listinfo/python-list
Re: Console UI
Clement typed: My project is based on console Application. Is there any console UI except urwid. If so, can i come to know. There is ``curses''. -- Ayaz Ahmed Khan Do what comes naturally now. Seethe and fume and throw a tantrum. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
Steven Bethard typed: Or, just: In [1]: l = [0024,haha,0024] In [2]: filter(lambda x: x != 0024, l) Out[2]: ['haha'] Only if you want to make your code harder to read and slower:: Slower, I can see. But harder to read? There really isn't much use for filter() anymore. Even in the one place I would have expected it to be faster, it's slower:: $ python -m timeit -s L = ['', 'a', '', 'b'] filter(None, L) 100 loops, best of 3: 0.789 usec per loop $ python -m timeit -s L = ['', 'a', '', 'b'] [i for i in L if i] 100 loops, best of 3: 0.739 usec per loop I am getting varying results on my system on repeated runs. What about itertools.ifilter()? $ python -m timeit -s L = ['0024', 'haha', '0024']; import itertools itertools.ifilter(lambda i: i != '1024', L) 10 loops, best of 3: 5.37 usec per loop $ python -m timeit -s L = ['0024', 'haha', '0024'] [i for i in L if i != '0024'] 10 loops, best of 3: 5.41 usec per loop $ python -m timeit -s L = ['0024', 'haha', '0024'] [i for i in L if i] 10 loops, best of 3: 6.71 usec per loop $ python -m timeit -s L = ['0024', 'haha', '0024']; import itertools itertools.ifilter(None, L) 10 loops, best of 3: 4.12 usec per loop -- Ayaz Ahmed Khan Do what comes naturally now. Seethe and fume and throw a tantrum. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
kyosohma typed: If you want to get really fancy, you could do a list comprehension too: your_list = [0024,haha,0024] new_list = [i for i in your_list if i != '0024'] Or, just: In [1]: l = [0024,haha,0024] In [2]: filter(lambda x: x != 0024, l) Out[2]: ['haha'] -- Ayaz Ahmed Khan Do what comes naturally now. Seethe and fume and throw a tantrum. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in python!? persistent value of an optional parameter in function!
Gabriel Genellina typed: See http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm Thanks for the link, Gabriel. I didn't know about this. -- Ayaz Ahmed Khan Falling in love makes smoking pot all day look like the ultimate in restraint. -- Dave Sim, author of Cerebus. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question
[EMAIL PROTECTED] typed: Tommy Grav schrieb: For this case, there are list comprehensions (or map, but you shouldn't use it any longer): I didn't see anything in the docs about this. Is map going away or is it considered un-Pythonic now? Most everywhere I've read about map() and filter() seemed to discourage their use stating that they're becoming depreciated (with the exception of Dive Into Python which advocates use of these two functions in preference to even list comprehensions, if I've read it properly). -- Ayaz Ahmed Khan Falling in love makes smoking pot all day look like the ultimate in restraint. -- Dave Sim, author of Cerebus. -- http://mail.python.org/mailman/listinfo/python-list
Something like the getattr() trick.
I'm working with the following class heirarchy (I've snipped out the code from the classes): class Vuln: def __init__(self, url): pass def _parse(self): pass def get_link(self): pass class VulnInfo(Vuln): pass class VulnDiscuss(Vuln): pass def main(url): vuln_class = ['Info', 'Discuss'] vuln = Vuln(url) vuln._parse() for link in vuln.get_link(): i = VulnInfo(link) i._parse() d = VulnDiscuss(link) d._parse() Is there a way to get references to VulnInfo and VulnDiscuss objects using something like the getattr trick? For example, something like: for _class in vuln_class: class_obj = getattr('Vuln%s' % (_class,) ..) a = class_obj(link) a._parse() getattr() takes an object as its first argument. I can't seem to figure out how to make it work here. -- Ayaz Ahmed Khan A witty saying proves nothing, but saying something pointless gets people's attention. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML Parsing
mtuller typed: I have also tried Beautiful Soup, but had trouble understanding the documentation As Gabriel has suggested, spend a little more time going through the documentation of BeautifulSoup. It is pretty easy to grasp. I'll give you an example: I want to extract the text between the following span tags in a large HTML source file. span class=titleLinux Kernel Bluetooth CAPI Packet Remote Buffer Overflow Vulnerability/span import re from BeautifulSoup import BeautifulSoup from urllib2 import urlopen soup = BeautifulSoup(urlopen('http://www.someurl.tld/')) title = soup.find(name='span', attrs={'class':'title'}, text=re.compile(r'^Linux \w+')) title u'Linux Kernel Bluetooth CAPI Packet Remote Buffer Overflow Vulnerability' -- Ayaz Ahmed Khan A witty saying proves nothing, but saying something pointless gets people's attention. -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing member
Paul McGuire typed: Here's a suggestion: use new-style classes. Have _BaseEntity inherit from object, allows you to use super for invoking methods on super classes. Instead of: class Entity(_BaseEntity): def __init__(self, type, x = 0, y = 0): _BaseEntity.__init__(self, type, x, y) You enter: class Entity(_BaseEntity): def __init__(self, type, x = 0, y = 0): super(Entity,self).__init__(type, x, y) This makes it easier to update your inheritance hierarchy later. New- style classes have other benefits too. I am still a beginner to Python, but reading that made me think on impluse, What happens in case of one class inheriting from two or more different classes? Having written a small test case and testing it, I find that super().__init__() calls the __init__() of the first of the class in the list of classes from which the calling class inherits. For example: class C(A, B): def __init__(self): super(C, self).__init__() calls A's __init__ explicity when an instance of C is instantiated. I might be missing something. I didn't know that. -- Ayaz Ahmed Khan A witty saying proves nothing, but saying something pointless gets people's attention. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question: ftp.storbinary()
Scott Ballard typed: Sorry for the lame question, I'm still trying to pick up Python and new to the list here. Question: I'm trying to write a python script that will access an FTP site and upload some files. I've gotten everything working except for the actual uploading of the files. I'm assuming that I should use storbinary( command, file[, blocksize]) to transfer the files. the documentation says command should be an appropriate STOR command: STOR filename. I can't seem to figure out an `appropriate STOR command' is??? It frustrated the hell out of me too until I found this: http://effbot.org/librarybook/ftplib.htm The following works: from ftplib import FTP ftp = FTP() ftp.set_debuglevel(2) ftp.connect(_host, _port) ftp.login(_user, _pass) ftp.storbinary('STOR ' + _file, open(_file)) ftp.quit() -- Ayaz Ahmed Khan A witty saying proves nothing, but saying something pointless gets people's attention. -- http://mail.python.org/mailman/listinfo/python-list