ANNOUNCE: PyGTK 2.8.2
I am pleased to announce version 2.8.2 of the Python bindings for GTK. The new release is available from ftp.gnome.org as and its mirrors as soon as its synced correctly: http://ftp.gnome.org/pub/GNOME/sources/pygtk/2.8/pygtk-2.8.2.tar.gz What's new since 2.8.1: - GIOChannel thread fix (Johan, Ole Andre Vadla Ravnås) For a complete list of new features in 2.8.x, see the wiki page: http://live.gnome.org/PyGTK/WhatsNew28 Blurb: GTK is a toolkit for developing graphical applications that run on POSIX systems such as Linux, Windows and MacOS X (provided that the X server for MacOS X has been installed). It provides a comprehensive set of GUI widgets, can display Unicode bidi text. It links into the Gnome Accessibility Framework through the ATK library. PyGTK provides a convenient wrapper for the GTK+ library for use in Python programs, and takes care of many of the boring details such as managing memory and type casting. When combined with PyORBit and gnome-python, it can be used to write full featured Gnome applications. Like the GTK+ library itself PyGTK is licensed under the GNU LGPL, so is suitable for use in both free software and proprietary applications. It is already in use in many applications ranging from small single purpose scripts up to large full features applications. PyGTK requires GTK+ = 2.8.0 and Python = 2.3 to build. Bug reports, as always, should go to Bugzilla; check out http://pygtk.org/developer.html and http://pygtk.org/feedback.html for links to posting and querying bug reports for PyGTK. -- Johan Dahlin [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Merging sorted lists/iterators/generators into one stream of values...
George Sakkis [EMAIL PROTECTED] wrote: ... manipulation of a heap to place an item in the right spot, but with 4-5 or a few more sources might not make an impact at all. Unless you're talking about hundreds or thousands sources, it probably won't. I would still go for the heap solution since IMO the resulting code it's more readable and easier to understand. I'm not so sure about either sentence...: Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100 --how=S Best time for 10 loops: 0.247116088867 Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100 --how=H Best time for 10 loops: 0.10344004631 i.e., a heap solution may be over 4 times faster than a sort-based one (in the following implementations). Readability seems quite comparable (skipping the rest of the infrastructure, which generates random sorted streams and ensures a stream is exhausted and verifies it etc etc): def merge_by_sort(streams): sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] while sources: sources.sort(reverse=True) best_source = sources[-1] yield best_source[0] try: best_source[0] = best_source[-1]() except StopIteration: sources.pop() def merge_by_heap(streams): sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] heapq.heapify(sources) while sources: best_source = sources[0] yield best_source[0] try: best_source[0] = best_source[-1]() except StopIteration: heapq.heappop(sources) else: heapq.heapreplace(sources, best_source) Hmmm, I wonder if something like merge_by_heap would be a good candidate for itertool. Raymond...? Alex -- http://mail.python.org/mailman/listinfo/python-list
Python Programmer Urgently Required
Job Description: The position holder will supplement the existing pool of application development and programming pool of OWSA technical team. In particular S/he will be responsible for developing Python based overlay application to be mounted on existing software tools and solutions. The position will report to Programe Manager, Training Technical Services. Required Skills: * A degree in Computer Application, Engineering or another numerate subject * 1+ years experience of web application development in Python or PHP * Good understanding of MySQL, PostGreSQL or another RDBMS platform. * Aptitude and experience of technical writing and process documentation * Good oral and written communication abilities; and ability to work in multi-disciplinary team To apply for any of these above positions, please send your latest resume along with details of your current role and how do your propose to contribute in this position. Women candidates with the requisite skills qualifications are especially encouraged to apply. OneWorld South Asia is an equal opportunity employer. Applications along with a one page write up explaining the suitability to the job may be sent (preferably through email) to: Kedar Dash Team Leader, Web Development OneWorld South Asia, C-5 Qutab Institutional Area New Delhi 110016 Tel: 91 11 51689001 Ext 108 Fax: 91 11 51689001 Email : [EMAIL PROTECTED] __ Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: searching a project to contribute to
Clint Norton wrote: Hi all, I'm a student currently in the beginning of my master's degree and I'm searching for an interesting open source project written in Python to contribute to. I have worked as a programmer for the past few years (mostly in academia but also as a typical full time code monkey in a commercial company), some of it in python, some in Java (commercial companies really seem to like Java). Anyway, which python projects would be a good start? I generally like working on algorithmic parts or Business Logic and really don't like doing interface work. The software I like producing has a tendency to make use of the random and/or math modules, if that says something about the nature of the work I've done... I really want to give something back to the community I've taken so much from in the past. We could always use more algorithms in scipy. scipy is a large, fairly loose collection of numerical algorithms. Currently we're in a transitional period; we're moving over to the new array object (yes, another one), so the website is a bit out of date. Fortunately, scipy is loose enough that you could simply jump in and implement a new algorithm without needing to concern yourself much with the rest of the library. I suggest poking around the latest SVN branches (listed below) to get a feel of what's already in there, and then introducing yourself on the scipy-dev list. I can give you more direct advice about what's missing and what we would like to include. http://scipy.org/ http://scipy.net/mailman/listinfo/scipy-dev http://svn.scipy.org/svn/scipy_core/branches/newcore/ http://svn.scipy.org/svn/scipy/branches/newscipy/ -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Pythot doc problem: lambda keyword...
i'm trying to lookup on the detail of language Python's “lambda” function feature. I've seen it before, but today i need to read about it again since i'm writing. I quickly went to the index page: http://python.org/doc/2.4.1/lib/genindex.html but all i got is a LambdaType. i'm thinking, maybe built-in functions are not listed there. Lo, but map() and friends are there. O, maybe i'm confused and “lambda” is actually a keyword by this particular language's feelings, but Lo, “while” is certainly a keyword but it is there. Fuck the Python liers and ignorant fuckheads. Motherfucking don't know shit and yet lying thru their teeth with fanfare. (for the technical context and justification of this message, please see the essays at the bottom of: http://xahlee.org/perl-python/python.html ) Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: non descriptive error
Timothy Smith wrote: i have reproduced the error in this code block #save values in edit self.FinaliseTill.SaveEditControlValue() if Decimal(self.parent.TillDetails[self.TillSelection.GetStringSelection()]['ChangeTinBalance'])) == Decimal('0'): #box must be checked before continuing if self.PlacedInSafe.GetValue() != 1: self.parent.Popup(You must place the till draw back in the safe,Till draw) else: #finalise the till draw if Decimal(self.TillFloat.GetLabel().split('$')[1]) != Decimal('0'): Prompt = wx.MessageDialog(self,The correct amount has not been returned from the till draw float to the main float! If you proceed please contact your manager,Change tin doesn't balance!,wx.YES_NO) if Prompt.ShowModal() == wx.ID_YES: self.Submit() else: self.parent.Popup('You have an outstanding change tin balance on this till','Change tin') i have NO idea what in there could be making it have such a strange error. it just says error when you try run it. there nothing terribly strange being done. the snippet you posted gives $ python script.py File script.py, line 2 self.FinaliseTill.SaveEditControlValue() ^ SyntaxError: invalid syntax on my python 2.3 install. are you sure you don't have some weird sitecustomize file on your machine? (more likely, it's a wxPython issue. can you reproduce this without using wxPython ?) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: non descriptive error
Timothy Smith wrote: it is definately a bug in 2.3 when using the decimal module. i can reproduce it. from decimal import Decimal a = Decimal('0' and when you attempt to run it you will get error $ python script.py File script.py, line 3 ^ SyntaxError: invalid syntax of course i do understand that decimal wasn't part of 2.3, but atleast now when if anyone gets that terse message they know where to start looking :) on your machine ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: __Classes and type tests
Brian van den Broek wrote: The code below exhibits an attempt to refer to the type of a __Class from within a method of that class. I've been unable to figure out how to make it work as I want, and would appreciate any insight. The problem emerged out of a bad design that the good folks on the tutor list helped me repair. With that repair, I no longer need nor want to do this sort of thing in actual code. But the academic issue How/Can it be done? still itches. Define the method outside the class to defeat mangling: def __init__(self): ... if type(self) == __Two: ... print two leading underscores ... class __Two(object): ... __init__ = __init__ ... __Two() two leading underscores __main__.__Two object at 0x4029360c Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: line
Shi Mu wrote_ There are four points with coordinates: 2,3;4,9;1,6;3,10. How to use Python to draw one perpendicular bisector between (2,3) and (4,9); the same was as you'd do it in any other computer language ? once you know the algorithm, implementing it in Python should be trivial. maybe you should look for some geometrics site/group first ? (sci.math or alt.math.recreational and their associated FAQs and archives might be good choices) (your questions do look a lot like homework assigments, btw. are you sure they're not homework? or if they are, that you're supposed to have others do you homework for you?) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: line
Why do you want to know? This list isn't a tool to get others to do your homework. Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: line
it is not a homework, just interested. On 10 Oct 2005 00:04:23 -0700, gsteff [EMAIL PROTECTED] wrote: Why do you want to know? This list isn't a tool to get others to do your homework. Greg -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on the Power PC
Peter Milliken wrote: There were Tkinter binaries with it so I installed those as well. When I attempt to run the most simplistic of python programs using Tkinter, I get an error message stating that Python can't find any tkinter module. Any ideas what I have done wrong anybody? what does import _tkinter say ? where is the _tkinter.so module (or whatever that's called on the pocket pc, or power pc, or what it is you're using) installed ? what is sys.path set to ? running python -vv -c 'import _tkinter' might provide you with additional clues. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on the Power PC
Peter Milliken wrote: Hi, I (think I have :-)) installed Python on my Pocket PC (obtained from http://fore.validus.com/~kashtan/). There were Tkinter binaries with it so I installed those as well. When I attempt to run the most simplistic of python programs using Tkinter, I get an error message stating that Python can't find any tkinter module. Any ideas what I have done wrong anybody? Thanks Peter import Tkinter if __name__ == '__main__': root = Tkinter.Tk() root.title('Hello World?') root.mainloop() Are you sure it didn't say _tkinter was what it couldn't find? On my Windows system the Tkinter.py file tries to import an extension (compiled C) module called _tkinter (provided as _tkinter.dll) that provides the low-level Tkinter functionality. It's likely that that's missing. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
changing filename of file-type object
I have a cgi script from which I wish to return a zipped file with an extension other than .zip (ie .zzz) I am creating a file-type object (cStringIO) and adding some zipped information to it using zipfile. I then return this with Content-Type: application/zip The problem is that the file the browser sees has a .zip extension. Is there any way I can change this extension? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythot doc problem: lambda keyword...
Xah Lee wrote: i'm trying to lookup on the detail of language Python's “lambda” function feature. google(site:docs.python.org lambda) -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you pronounce wxpython
I always pronounced it double-you-ex-python. I am almost positive this is the way it is pronounced. Although the wxPyWiki seems to be pronounced wix-pee-wi-kee (as it says on the front page) so maybe it is pronounced wix-Python... you never know... HTH, Peter Alex wrote: My native language is not English so I just wonder how you pronounce wxPython. vi-ex python double-you-ex python wax-python or something else Thanks -- http://mail.python.org/mailman/listinfo/python-list
Comparing lists
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and Y contains all the elements that are B but not in A. Z will then have the elements that are in both A and B. One way of doing this is of course to iterate throug the lists and compare each of the element, but is there a more efficient way? Thanks in advance! -- Har du et kjøleskap, har du en TV så har du alt du trenger for å leve -Jokke Valentinerne -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythot doc problem: lambda keyword...
Xah Lee เขียน: i'm trying to lookup on the detail of language Python's “lambda” function feature. I've seen it before, but today i need to read about it again since i'm writing. I quickly went to the index page: http://python.org/doc/2.4.1/lib/genindex.html but all i got is a LambdaType. i'm thinking, maybe built-in functions are not listed there. Lo, but map() and friends are there. O, maybe i'm confused and “lambda” is actually a keyword by this particular language's feelings, but Lo, “while” is certainly a keyword but it is there. Fuck the Python liers and ignorant fuckheads. Motherfucking don't know shit and yet lying thru their teeth with fanfare. (for the technical context and justification of this message, please see the essays at the bottom of: http://xahlee.org/perl-python/python.html ) Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ I knew I shouldn't feed the troll, but anyway. 'lambda' is a keyword. So there's no doubt looking in LIBRARY Reference and not finding it. There exists a document called LANGUAGE Reference, with description of 'lambda' keyword. http://python.org/doc/2.4.1/ref/lambdas.html. ('while' statement is also documented in Language Reference.) So to quote from Xah Lee: Fuck the [...] ignorant fuckheads. Motherfucking don't know shit and yet lying thru their teeth [...]. You can't complain about lacks of knowledge if you don't know where to look. BTW, you post to the wrong group. Regards, -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
Odd-R. wrote: I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and Y contains all the elements that are B but not in A. Z will then have the elements that are in both A and B. These are set operations. One way of doing this is of course to iterate throug the lists and compare each of the element, but is there a more efficient way? Maybe, using sets? L1 = [1,2,3,4] L2=[3,4,5,6] diff1 = list(set(L1)-set(L2)) # [1,2] diff2 = list(set(L2)-set(L1)) # [5,6] symdiff = diff1+diff2 # Symmetric difference [1,2,5,6] intersect = set(L1+L2) - set(symdiff) # Intersect [3,4] Best, Les -- http://mail.python.org/mailman/listinfo/python-list
Re: users of pycurl here?
The Effbot wrote: here's a robust parser for various LIST output formats: http://cr.yp.to/ftpparse.html (google for ftpparse to find python bindings for that module) Well, I have downloaded the one from your site (ftpparse-1.1-20021124) and I have given a python setup.py install. Now I have a _ftpparse.so which exposes a single function 'parse'. However both the module and the function do not have any docstring, the underscore makes me believe that there should be a ftpparse.py file which is missing, and the README says for a usage example, see the sanity.py test script but there is not such a script in the distribution :-( Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Question about parsing a string
Hi there, I would like to parse a string in Python. If the string is e.g. '[url=http://www.whatever.org][/url]' I would like to generate this string: 'a href=http://www.whatever.org;http://www.whatever.org/a' If the string is e.g. '[url=http://www.whatever.org]My link[/url]' I would like to generate this string: 'a href=http://www.whatever.org;My link/a' Any idea how I can do this? Maybe with regular expressions? Thanks in advance, Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
try to use set. L1 = [1,1,2,3,4] L2 = [1,3, 99] A = set(L1) B = set(L2) X = A-B print X Y = B-A print Y Z = A | B print Z Cheers, pujo -- http://mail.python.org/mailman/listinfo/python-list
Re: no variable or argument declarations are necessary.
Op 2005-10-07, Diez B. Roggisch schreef [EMAIL PROTECTED]: Well, that exactly is the point where we make the transition from this is how things work to pure speculation. Everything starts with pure speculation. I had no intention of introducing the big type system here. I just think people who oppose type systems, limit themselves too much to how things currently work and from there oppose anything that resembles a type system instead of thinking of what they would like a type system to do even if it is not implemtable now. Can't say that there won't be a solution someday - but certainly it requires much more, and from above nobody can say that this would solve _any_ problem. What you propose above is what JAVA does - plus more dynamicity. So it isn't exactly JAVA afterall. Well, given that even the non-dynamic, everything has to be annotated JAVA fails to deal with ANY (called Object there), So please explain how my system fails with the ANY. I can't see how a more dynamic environment will do _better_ in that respect. You first argued that a type system had to limit the coder and you gave the example of the homegeneous list. I suggested an ANY type and asked how a homegeneous list of ANY's would limit the coder. Your respons was that this was like a JAVA Object or C void* hack, that can be used to circumvent the type system and cause all kinds of problems, presumebly python was not vulnerable to. So I would either like you to explain how my idea can be used to circumvent the type system and cause problems, which don't concern python or explain how this system will limit the coder with respect what can be done in python. So unless you lay out some more detailed ideas how that works, this surely won't do much if any better than JAVA does today - and JAVA sucks _precisely_ because of the half-static-half-dynamic nature. It gives you both troubles - runtime errors like in python, together with compile-time limitations. I have no need to convince you. It was you who made this claim how a type system had to limit the coder. That you can't see how it could be done is not an argument. Surely if a typesystem *must* limit the user or else cause all kinds of problems as more general argument can be given that doesn't depend on the specific implementation. Let's face it: you don't know much about type-systems. I do know a bit more - but don't claim to possess the holy grail. And I don't say that more powerful analyzing isn't possible. However, all you do so far is fantasizing and fail to see why not. Well, that failure might be because of limited sight on your side - not necessarily on our, which you constantly claim. Well, I could accept that if you would have explained what the problem would be with my system instead of just saying you couldn't see how it would be more usefull than JAVA Objects. Visions are a nice thing - but actually, in the scientific domain not so much a vision, but proofs are what is needed. Well you made the claim that a type system had to limit the coder. Now prove your claim. Untill this is done I see no problem thinking about type systems that don't limit the coder. And if you consider it hostile that nobody buys your ideas because so far they aren't more than marketing/whishful thinking, I'm sorry that I can't help you. I don't consider it hostile that nobody buys my ideas. I considered the environment here hostile to type systems long before I brought my two cents to the discussions about this subject here. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
2D graphics
Hello, As a Python beginner, I feel a bit lost among all possible libraries... so I wondered whether soemone could help me find my way... I just need to generate animated sequences of 2D primitives (dots and lines), as fast as possible, checking the computer clock for the time elapsed for each image, and checking the mouse click. Thanks a lot in advance for your help! Valerie, agrateful Pythonner -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about parsing a string
Nico Grubert wrote: I would like to parse a string in Python. If the string is e.g. '[url=http://www.whatever.org][/url]' I would like to generate this string: 'a href=http://www.whatever.org;http://www.whatever.org/a' If the string is e.g. '[url=http://www.whatever.org]My link[/url]' I would like to generate this string: 'a href=http://www.whatever.org;My link/a' Any idea how I can do this? Maybe with regular expressions? here's one way to do it: import re, cgi def fixurl(text): def fixup(m): link, text = m.groups() text = text.strip() or link return a href='%s'%s/a % (cgi.escape(link), cgi.escape(text)) return re.sub(r\[url=([^]]+)\]([^[]*)\[/url\], fixup, text) usage: fixurl([url=http://www.whatever.org][/url];) a href='http://www.whatever.org'http://www.whatever.org/a fixurl([url=http://www.whatever.org]My link[/url]) a href='http://www.whatever.org'My link/a /F -- http://mail.python.org/mailman/listinfo/python-list
Re: 2D graphics
Peres wrote: As a Python beginner, I feel a bit lost among all possible libraries... so I wondered whether soemone could help me find my way... I just need to generate animated sequences of 2D primitives (dots and lines), as fast as possible, checking the computer clock for the time elapsed for each image, and checking the mouse click. animated as in animated on screen ? all Python GUI toolkits can do that. which one(s) do you have installed on your machine? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about parsing a string
Nico Grubert [EMAIL PROTECTED] wrote: Hi there, I would like to parse a string in Python. If the string is e.g. '[url=http://www.whatever.org][/url]' I would like to generate this string: 'a href=http://www.whatever.org;http://www.whatever.org/a' If the string is e.g. '[url=http://www.whatever.org]My link[/url]' I would like to generate this string: 'a href=http://www.whatever.org;My link/a' Any idea how I can do this? Maybe with regular expressions? If you know the string always starts with '[url=' and ends with '[/url]' (or, any string not thus starting/ending are to be skipped, etc), REs are a bit of an overkill (they'll work, but you can do it more simply). If your actual needs are different, you'll have to express them more explicitly. But assuming the given starting and ending scenario: _start = '[url=' _startlen = len(_start) _end = '[/url]' _endlen = len(_end) def doit(s): if s[:_startlen] != _start: raise ValueError if s[-_endlen:] != _end: raise ValueError where_closebracket = s.index(']') url = s[_startlen:where_closebracket] txt = s[where_closebracket+1:-_endlen] if not txt: txt = url return 'a href=%s%s/a' % (url, txt) I've just typed in this code without trying it out, but roughly it should be what you want. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Roedy Green [EMAIL PROTECTED] writes: On Sat, 08 Oct 2005 23:33:13 GMT, Rich Teer [EMAIL PROTECTED] wrote or quoted : What the hell has that got to do with HTML email? Sending photos is an example of what attachments are for. Normally you send photos to grandma with captions under each photo. That is far more convenient for the technopeasant receiver than dealing with multiple attachments. I'd like to agree, but I haven't received *ANY* properly formatted, captioned and readable list of photos in an HTML email message in a long while. What I usually get it an email message with a completely irrelevant subject -- usually a reply to a random thread that happened to include my email address in the recipient list -- with a message body as useless as: Here's a photo collection or even more useless, or empty. This and other things, that show the original poster of the particular HTML email message has _no_ intention to spend just *one* minute to properly write a readable, useful email message, tend to be the main reasons why I block all HTML email messages from non-work-related email addresses, save them in a special folder and look at them only when I really feel like spending some time to weed through the junk. -- http://mail.python.org/mailman/listinfo/python-list
2D graphics
Dear Fredrik, Thanks for your answer. yes it means animated on the screen. I downloaded Python2.4, pygame and vision, but the animation is slow, and i cannot set a graphic priority to my program. Someone suggested PyopenGL.sourceforge, but it seems complicated. Thanks again Valerie -- http://mail.python.org/mailman/listinfo/python-list
Re: users of pycurl here?
Michele Simionato wrote: the README says for a usage example, see the sanity.py test script but there is not such a script in the distribution :-( looks like a distutils glitch... try this one: # $Id$ # minimal sanity check import string TESTS = [ # examples taken from ftpparse.c, +i8388621.29609,m824255902,/,\tdev, +i8388621.44468,m839956783,r,s10376,\tRFCEPLF, -rw-r--r-- 1 root other531 Jan 29 03:26 README, dr-xr-xr-x 2 root other512 Apr 8 1994 etc, dr-xr-xr-x 2 root 512 Apr 8 1994 etc, lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin - usr/bin, 04-27-00 09:09PM DIR licensed, 07-18-00 10:16AM DIR pub, 04-14-00 03:47PM 589 readme.htm, ] import _ftpparse # parse sample strings for line in TESTS: print repr(line), - try: item = _ftpparse.parse(line) except ValueError: print ***, cannot parse this line else: print, (item.name, item.size, item.mtime, item.id, item.trycwd) # check behaviour for unknown attributes try: item.unknown except AttributeError: pass # end on my machine, this prints: '# examples taken from ftpparse.c' - *** cannot parse this line '+i8388621.29609,m824255902,/,\tdev' - ('dev', None, 824255902, '8388621.29609', True) '+i8388621.44468,m839956783,r,s10376,\tRFCEPLF' - ('RFCEPLF', 10376, 839956783, '8388621.44468', False) '-rw-r--r-- 1 root other531 Jan 29 03:26 README' - ('README', 531, 1106969160, None, False) 'dr-xr-xr-x 2 root other512 Apr 8 1994 etc' - ('etc', 512, 765763200, None, True) 'dr-xr-xr-x 2 root 512 Apr 8 1994 etc' - ('etc', 512, 765763200, None, True) 'lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin - usr/bin' - ('bin', 7, 1106612220, None, True) '04-27-00 09:09PM DIR licensed' - ('licensed', None, 956869740, None, True) '07-18-00 10:16AM DIR pub' - ('pub', None, 963915360, None, True) '04-14-00 03:47PM 589 readme.htm' - ('readme.htm', 589, 955727220, None, False) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
In article [EMAIL PROTECTED], Paul Rubin wrote: I would say give the app the heaviest stress testing that you can before deploying it, checking carefully for leaks and crashes. I'd say that regardless of the implementation language. Goes without saying. But I would like to be confident (or as confident as possible) that all bugs are mine. If I use plain C, I think this is the case. Of course, bad memory management in the underlying platform will wreak havoc. I am planning to use Linux 2.4.somethingnew as the OS kernel, and there I have not experienced too many problems before. Adding the Python interpreter adds one layer on uncertainty. On the other hand, I am after the simplicity of programming offered by Python. - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) -- http://mail.python.org/mailman/listinfo/python-list
Re: assigning in nested functions
Op 2005-10-09, jena schreef [EMAIL PROTECTED]: Hi I have code # BEGIN CODE def test(): def x(): print a a=2 # *** a=1 x() print a test() # END CODE This code fails (on statement print a in def x), if I omit line marked ***, it works (it prints 1\n1\n). It look like when I assign variable in nested function, I cannot access variable in container function. I need to assign variable in container function, is any way to do this? I think the best solution with current python in this situation is to wrap the nested scope variable in a one element list and use slice notation to change the variable in a more nested function. Something like the following: def test(): def x(): print a[0] a[:] = [2] a = [1] x() print a[0] test() Another solution, IMO more workable if you have more of these variables is to put them all in a Scope object aka Rec, Bunch and probably some other names and various implementatiosn. (I don't remember from who this one is. Something like the following: class Scope(object): def __init__(__, **kwargs): for key,value in kwargs.items(): setattr(__, key, value) __getitem__ = getattr __setitem__ = setattr def test(): def x(): print scope.a scope.a = 2 scope = Scope(a=1) x() print scope.a test() -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
In article [EMAIL PROTECTED], Steven D'Aprano wrote: If performance is really not such an issue, would it really matter if you periodically restarted Python? Starting Python takes a tiny amount of time: Uhhh. Sounds like playing with Microsoft :) I know of a mission- critical system which was restarted every week due to some memory leaks. If it wasn't, it crashed after two weeks. Guess which platform... $ time python -c pass real0m0.164s user0m0.021s sys 0m0.015s This is on the limit of being acceptable. I'd say that a one-second time lag is the maximum. The system is a safety system after all, and there will be a hardware watchdog to take care of odd crashes. The software itself is stateless in the sense that its previous state does not affect the next round. Basically, it is just checking a few numbers over the network. Even the network connection is stateless (single UDP packet pairs) to avoid TCP problems with partial closings, etc. There are a gazillion things which may go wrong. A stray cosmic ray may change the state of one bit in the wrong place of memory, and that's it, etc. So, the system has to be able to recover from pretty much everything. I will in any case build an independent process which probes the state of the main process. However, I hope it is never really needed. I'm not saying that you will need to restart Python once an hour, or even once a month. But if you did, would it matter? What's more important is the state of the operating system. (I'm assuming that, with a year uptime the requirements, you aren't even thinking of WinCE.) Not even in my worst nightmares! The platform will be an embedded Linux computer running 2.4.somethingnew. - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) -- http://mail.python.org/mailman/listinfo/python-list
Python and windows
I've designed a virtual keyboard (on screen)with Python. I've used Pithonwin and Tkinter. Well, I'd like to use this keyboard with some Windows's Application. This keyboard should find which application is running (with an Active window) and then write on it. The keybord should remain always on desktop. I've wrote a script that interacts with Word. I've created a COM object with 'win32com.client.Dispatch('Word.Application')'. But I'm not very happy of this solution because I'd like to create the object only if Word is really running. So for all (or almost all) Windows's Applications. I'm sorry for my bad english. Thanks for your time for me. -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
al [EMAIL PROTECTED] wrote: And it solve a problem that in all object oriented langages, a method that process 2 or more different classes of objets belongs just to one of those classes. Your use of the word all in the phrase all object oriented languages is erroneous. There ARE several object-oriented languages which solve this issue neatly and elegantly by using multi-methods. The most easily accessible of those is probably still Dylan; see http://www.double.co.nz/dylan/ for more I don't believe that Python will ever have multi-methods (any more than I expect to see them in Java, C++ or C#), but that's no reason to forget them:-). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python book
hrh1818 [EMAIL PROTECTED] wrote: This book is not a new book. It is an updated version of Magnus's 2002 Practical Python book. Then it's probably a good book, because Practical Python sure was! Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
Ville Voipio [EMAIL PROTECTED] writes: Goes without saying. But I would like to be confident (or as confident as possible) that all bugs are mine. If I use plain C, I think this is the case. Of course, bad memory management in the underlying platform will wreak havoc. I am planning to use Linux 2.4.somethingnew as the OS kernel, and there I have not experienced too many problems before. You might be better off with a 2.6 series kernel. If you use Python conservatively (be careful with the most advanced features, and don't stress anything too hard) you should be ok. Python works pretty well if you use it the way the implementers expected you to. Its shortcomings are when you try to press it to its limits. You do want reliable hardware with ECC and all that, maybe with multiple servers and automatic failover. This site might be of interest: http://www.linux-ha.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: users of pycurl here?
Yes, it works fine, thanks (still I am a bit surprised there is not ftpparse.py but only an _ftpparse.so). Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
Ville Voipio wrote: There are a gazillion things which may go wrong. A stray cosmic ray may change the state of one bit in the wrong place of memory, and that's it, etc. So, the system has to be able to recover from pretty much everything. I will in any case build an independent process which probes the state of the main process. However, I hope it is never really needed. If you have enough hardware grunt, you could think about having three independent processes working in parallel. They vote on their output, and best out of three gets reported back to the user. In other words, only if all three results are different does the device throw its hands up in the air and say I don't know! Of course, unless you are running each of them on an independent set of hardware and OS, you really aren't getting that much benefit. And then there is the question, can you trust the voting mechanism... But if this is so critical you are worried about cosmic rays, maybe it is the way to go. If it is not a secret, what are you monitoring with this device? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
propagating distutil user options between commands
When building a C extension, Distutils standard command 'install' calls the 'build' command before performing the installation (see Lib/distutils/command/install.py and build.py). Reusing the build command is the correct way to ensure the installation payload is ready, but the two commands support very different sets of user options and it is impossible to combine them: install validates them at the beginning, rejecting user options meant for build as unrecognized. This becomes a problem with necessary build options like --compiler; there is an easy workaround for my specific case (running setup.py twice: build --compiler=... then install --skip-build), but --skip-build is an ad hoc option, other combinations of commands and options can have the same problem. There are systematic solutions, like letting every option propagate to subcommands without checking, on the assumption that unrecognized options do no harm, or labeling options by command (e.g. setup.py install --build:compiler=foo --install_scripts:force) to let every command validate its options only and limit options to specific commands as a byproduct. What are the reasons for the current strict policy in Distutils? Can it be changed? Lorenzo Gatti -- http://mail.python.org/mailman/listinfo/python-list
Perl-Python-a-Day: Sorting
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: li=[1,9,2,3]; li.sort(); print li; Note that sort is a method, and the list is changed in place. Suppose you have a matrix, and you want to sort by second column. Example Solution: li=[[2,6],[1,3],[5,4]] li.sort(lambda x, y: cmp(x[1],y[1])) print li; # prints [[1, 3], [5, 4], [2, 6]] The line “li.sort(lambda x, y: cmp(x[1],y[1]))” can also be written as “li.sort(cmp=lambda x, y: cmp(x[1],y[1]))” The argument to sort is a function of two arguments, that returns -1, 0, 1. This function is a decision function that tells sort() how to decide the order of any two elements in your list. If the first argument is “less” then second argument, the function should return -1. If equal, then 0. Else, 1. Here's a more complex example. Suppose you have a list of strings. 'my283.jpg' 'my23i.jpg' 'web7-s.jpg' 'fris88large.jpg' ... You want to sort them by the number embedded in them. What you have to do, is to provide sort() method a function, that takes two strings, and compares the integer inside the string. Here's the solution: li=[ 'my283.jpg', 'my23i.jpg', 'web7-s.jpg', 'fris88large.jpg', ] def myComp (x,y): import re def getNum(str): return float(re.findall(r'\d+',str)[0]) return cmp(getNum(x),getNum(y)) li.sort(myComp) print li # returns ['web7-s.jpg', 'my23i.jpg', 'fris88large.jpg', 'my283.jpg'] Here, we defined a function myComp to tell sort about the ordering. Normally, one would use the “lambda” construct, but Python's lambda construct can only represent the simplest functions. Some Math about Sorting In general, the function f used to determine the order of any two element must satisfy some constraints: • f(a,a)==0 • if f(a,b)==0 then f(b,a)==0 • if f(a,b)==0 and f(b,c)==0, then f(a,c)==0. • if f(a,b)==-1 and f(b,c)==-1, then f(a,c)==-1. • if f(a,b)==-1, then f(b,a)==1. If the comparison function does not behave as the above, then it is not consistent, meaning that the result “ordered” list is may actually be different depending how the language happens to implement sort. The significance of all these is that in real software you may want to sort a list of non-simple entities by a specialized ordering. For example, you may want to sort a list of polygonal surfaces in 3D space, for particular reasons in implementing some computer graphics features. Say, you want to sort these polygons by their spacial orientations. It is in advanced cases like these, understanding the basic math about ordering is important. Otherwise, you might have a bewildering result yet unable to locate any flaws in your code. Python's “sort” method's optional parameters: “key” and “reverse” Most of the time, sorting is done for a list of atomic element such as [3,2,4]. This is simply done by myList.sort() without any argument. Other than simple list, sort is frequently used on matrixes (e.g. [[2,6],[1,3],[5,4]]). For matrixes, almost always a particular column is used for the basis of ordering. For example, if we want to sort by second column, we do: “li.sort(lambda x, y: cmp(x[1],y[1]))”. Since this is frequently used, Python provides a somewhat shorter syntax for it, by specifying the column used as the ordering “key”. For example: li=[[2,6],[1,3],[5,4]] li.sort(key=lambda x:x[1] ) # is equivalent to the following #li.sort(lambda x, y: cmp(x[1],y[1])) print li; # prints [[1, 3], [5, 4], [2, 6]] Because Python's implementation is not very refined , this specialized syntax is actually much speedier than the general form “lambda x, y: cmp(x[1],y[1])”. It is a burden on the programer to always use the “key” syntax idiosyncrasy if he is sorting a large matrix. Another idiosyncratic provision is the optional “reverse” argument. This parameter is somewhat necessary when using the “key” parameter. One can reverse the ordering by using the “reverse” keyword as a argument to sort. Example: The following are equivalent: li.sort(key=lambda x:x[1], reverse=True ) li.sort(lambda x, y: cmp(x[1],y[1]), reverse=True) li.sort(lambda x, y: cmp(y[1],x[1])) The official doc on Python's sort method is at (bottom): http://python.org/doc/2.4/lib/typesseq-mutable.html Sorting in Perl (to be posted in a couple of days) This post is archived at: http://xahlee.org/perl-python/sort_list.html Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: searching a project to contribute to
Thank you all for your advice, I currently have several offers that I'm really tempted about - I will take a closer look at both of them (as well as continue searching) and will make an educated decision within the next few days. I've also decided to get rid of the sily pseudonym... -- http://mail.python.org/mailman/listinfo/python-list
Writing an xmgr/grace file as text (not interactive)
Can someone suggest a package that allows me to write a data file for xmgr. So far I have found some packages that allow me to start an interactive xmgrace session from python, but I would rather have a package that write a text file. I realize that xmgr can read text-files, and that the format of an xmgr-file is easy to read, but if someone has allready done this work then I would rather steal it and save my own time :) Thanks in advance Niels -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about StringIO
Diez B. Roggisch wrote: Frank Millman wrote: Hi all I understand that StringIO creates a file-like object in memory. Is it possible to invoke another program, using os.system() or os.popen(), and use the redirect operator, so that the other program reads my StringIO object as its input? No. Processes don't share memory - thus you have to either use a temp file, or pipes. BTW, I have tried using popen2() and passing my data via stdin, but the other program (psql) does not react well to this - again, I will give more info if necessary. Better do so :) Diez Thanks, Steve and Diez, for the replies. I didn't think it was possible, but it was worth asking :-) I will try to explain my experience with popen() briefly. I have some sql scripts to create tables, indexes, procedures, etc. At present there are about 50 scripts, but this number will grow. I have been running them manually so far. Now I want to automate the process. I am supporting PostgreSQL and MS SQL Server, and the syntax is slightly different in some cases. Rather than maintain two sets of scripts, I prefix some lines with -pg- or -ms- to indicate the platform, and then use Python to parse the scripts and generate a correct output for each platform, passing it to 'psql' and 'osql' respectively, using popen(). I have had a few problems, but it would take too long to describe them all, and I just want a working solution, so I will focus on my latest attempt. I run through all the scripts and create a StringIO object with the string I want to pass. It is about 250 000 bytes long. If I run psql using popen(), and pass it the string via stdin, it works fine, but I get all the messages on the screen. If I do the same, but end the command with ' fjm 21' it works correctly and the messages end up in the file fjm, which is about 40 000 bytes long. If I run it with popen4(), it starts ok, but then hangs about 1/4 of the way through. Exactly the same happens on MSW. It seems to be hitting a limit on the size of the stdout file - is that possible? For my purposes, I will be happy to use popen() and a choice of no redirection, redirect to a file, or redirect to /dev/null. The question about popen4() is therefore academic, though I would be interested to know the answer. BTW, is there an equivalent of /dev/null on MSW? Thanks in advance for any suggestions. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl-Python-a-Day: Sorting
Followup-To: comp.lang.scheme Xah Lee [EMAIL PROTECTED] writes: Since this is frequently used, Python provides a somewhat shorter syntax for it, by specifying the column used as the ordering “key”. [...] Because Python's implementation is not very refined , this specialized syntax is actually much speedier than the general form “lambda x, y: cmp(x[1],y[1])”. It is a burden on the programer to always use the “key” syntax idiosyncrasy if he is sorting a large matrix. It's not only clearer for a human, but also faster in all good implementations of all languages which support that, except when the ordering function is very simple. It's called Schwartzian transform and I wish more language designers and programmers knew about it. http://en.wikipedia.org/wiki/Schwartzian_transform I urge future SRFI authors to include it. The withdrawn SRFI-32 for sorting didn't do that, and I can't find any other SRFI which deals with sorting. -- __( Marcin Kowalczyk \__/ [EMAIL PROTECTED] ^^ http://qrnik.knm.org.pl/~qrczak/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuous system simulation in Python
Nicolas, I am aware of some shortcomings and design flaws of Simulink, especially in the code generation area. I am interested by your paper nonetheless, please send me copy. However, Simulink is used by many people on a day-to-day basis in the context of big, industrial projects. The claim that it is next to unusable is, in my book, an overstatement ... Scicos is not perfect either but you can hardly say that is is a simple clone of Simulink. No time and space to go into the details ... Obviously, the python community is very dynamic, but how much support will you get in the very specific topic of continuous time systems simulation ? IMHO, an hybrid approach, such as the development of bridge to include Python components into Simulink/Scicos/Ptolemy/ Modelica/pick_your_favorite_simulator may grant you more interest from the simulation community. Cheers, SB Nicolas Pernetty wrote: Simulink is well fitted for small simulators, but when you run into big projects, I find many shortcomings appears which made the whole thing next to unusable for our kind of projects. That's why I'm interested in Python by the way, it is not a simple clone like Scilab/Scicos. It is a real language which bring its own advantages, and its own shortcomings, which I find well suited for our activity. If you want, I can send you a paper I wrote last year, detailing all Simulink shortcomings. I doubt that this mailing list is interested in such things...(and it's in French...). Concerning Scilab/Scicos, I'm not really interested in a technology primarily developed (INRIA and ENSPC) and used by France. Python and all its libraries and communities are so much more dynamic ! And also I've heard that Scilab was developed in Fortran in a way which make it rigid and that the sources are poorly documented, not a good sign for an open source software (and Scilab isn't 'Free' for the FSF). Regards, *** REPLY SEPARATOR *** On 8 Oct 2005 11:06:25 -0700, Sébastien Boisgérault [EMAIL PROTECTED] wrote : Simulink is a framework widely used by the control engineers ... It is not *perfect* but the ODEs piece is probably the best part of the simulator. Why were you not convinced ? You may also have a look at Scicos and Ptolemy II. These simulators are open-source ... but not based on Python. Cheers, SB Nicolas Pernetty a écrit : Hello Phil, Yes I have considered Octave. In fact I'm already using Matlab and decided to 'reject' it for Python + Numeric/numarray + SciPy because I think you could do more in Python and in more simple ways. Problem is that neither Octave, Matlab and Python offer today a framework to build continuous system simulator (in fact Matlab with Simulink and SimMechanics, do propose, but I was not convinced at all). Regards, *** REPLY SEPARATOR *** On 7 Oct 2005 11:00:54 -0700, [EMAIL PROTECTED] wrote : Nicholas, Have you looked at Octave? It is not Python, but I believe it can talk to Python. Octave is comparable to Matlab for many things, including having ODE solvers. I have successfully used it to model and simulate simple systems. Complex system would be easy to model as well, provided that you model your dynamic elements with (systems of) differential equations. -- http://mail.python.org/mailman/listinfo/python-list
Changing an AST
Is it possible compiler.parse a statement, then change and then execute/resolve it? Background: I'm probably to lazy to write my own parser. I have such a statement as string: distance = x**2 + y**2 x and y are undefined, so it is no executable Python code, but it is parseable. Now i'd like traverse through the AST and change Name('x') for the value i have elsewhere. And finally let Python resolve the computation. More Background: I want to write a simulation game with many interdepended values. I don't want to create a class with dozens of functions, but let Python create/evaluate them. I hope this can be understood ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: dcop module under Python 2.4
Hi Diez, thank you for your replay, but I didn't succeed (I am almost a newbye). So I solved the problem in another manner: I changed distribution from kubuntu to SUSE 9.3 (base installation). Now I can import dcop and also pcop. Bye. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing an AST
beza1e1 [EMAIL PROTECTED] wrote: I have such a statement as string: distance = x**2 + y**2 x and y are undefined, so it is no executable Python code, but it is parseable. Now i'd like traverse through the AST and change Name('x') for the value i have elsewhere. And finally let Python resolve the computation. you can use the parser class for this purpose: http://www.effbot.org/librarybook/parser.htm instead of manipulating the parse tree, you can use the AST to identify the variables, create a dictionary with the current values, and use exec or eval to evaluate it. or you can use a regular expression to dig out all variable names. or you can compile the expression and analyze the code object to find the variable names, and use the dictionary/exec approach: expr = compile(distance = x**2 + y**2, , exec) expr.co_varnames ('distance',) list(set(expr.co_names) - set(expr.co_varnames)) ['y', 'x'] context = {x: 10, y: 20} exec expr in context context[distance] 500 (the regular expression approach is probably the only one that's guaranteed to work on all python implementations) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
In article [EMAIL PROTECTED], Steven D'Aprano wrote: If you have enough hardware grunt, you could think about having three independent processes working in parallel. They vote on their output, and best out of three gets reported back to the user. In other words, only if all three results are different does the device throw its hands up in the air and say I don't know! Ok, I will give you a bit more information, so that the situation is a bit clearer. (Sorry, I cannot tell you the exact application.) The system is a safety system which supervises several independent measurements (two or more). The measurements are carried out by independent measurement instruments which have their independent power supplies, etc. The application communicates with the independent measurement instruments thrgough the network. Each instrument is queried its measurement results and status information regularly. If the results given by different instruments differ more than a given amount, then an alarm is set (relay contacts opened). Naturally, in case of equipment malfunction, the alarm is set. This covers a wide range of problems from errors reported by the instrument to physical failures or program bugs. The system has several weak spots. However, the basic principle is simple: if anything goes wrong, start yelling. A false alarm is costly, but not giving the alarm when required is downright impossible. I am not building a redundant system with independent instruments voting. At this point I am trying to minimize the false alarms. This is why I want to know if Python is reliable enough to be used in this application. By the postings I have seen in this thread it seems that the answer is positive. At least if I do not try apply any adventorous programming techniques. - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing an AST
beza1e1 wrote: Is it possible compiler.parse a statement, then change and then execute/resolve it? This should work: from compiler.pycodegen import ModuleCodeGenerator from compiler.misc import set_filename from compiler import parse tree = parse('foo = 42') set_filename('foo', tree) code = ModuleCodeGenerator(tree).getCode() exec code foo 42 Also, if you need to turn an AST back into Python code, I have some ugly code for doing that: http://ecritters.biz/asttosource.py. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
In article [EMAIL PROTECTED], Paul Rubin wrote: You might be better off with a 2.6 series kernel. If you use Python conservatively (be careful with the most advanced features, and don't stress anything too hard) you should be ok. Python works pretty well if you use it the way the implementers expected you to. Its shortcomings are when you try to press it to its limits. Just one thing: how reliable is the garbage collecting system? Should I try to either not produce any garbage or try to clean up manually? You do want reliable hardware with ECC and all that, maybe with multiple servers and automatic failover. This site might be of interest: Well... Here the uptime benefit from using several servers is not eceonomically justifiable. I am right now at the phase of trying to minimize the downtime with given hardware resources. This is not flying; downtime does not kill anyone. I just want to avoid choosing tools which belong more to the problem than to the solution set. - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing an AST
Thank you! this compile/exec in context is the thing i wanted. It is not that performant i think. But it should ease the prototyping. -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl-Python-a-Day: Sorting
Xah Lee wrote: To sort a list in Python, use the “sort” method. For example: li=[1,9,2,3]; li.sort(); print li; Likewise in Common Lisp. In Scheme there are probably packages for that as well. My apologies for not being very fluent anymore. CL-USER (setf list (sort '(1 9 2 3) #')) ; input (1 2 3 9) ; output The second argument is mandatory too (comparison function). Note that sort is a method, and the list is changed in place. Same here. To be safe, assign the result to list. Suppose you have a matrix, and you want to sort by second column. Example Solution: li=[[2,6],[1,3],[5,4]] li.sort(lambda x, y: cmp(x[1],y[1])) print li; # prints [[1, 3], [5, 4], [2, 6]] CL-USER (setf list (sort '((2 6) (1 3) (5 4)) #'(lambda (x y) ( (second x) (second y) ((1 3) (5 4) (2 6)) ; output The argument to sort is a function of two arguments, that returns -1, 0, 1. This function is a decision function that tells sort() how to decide the order of any two elements in your list. If the first argument is “less” then second argument, the function should return -1. If equal, then 0. Else, 1. In CL you only need a smaller-than function. I guess if elements are equal, they don't need sorting anyway. li=[ 'my283.jpg', 'my23i.jpg', 'web7-s.jpg', 'fris88large.jpg', ] CL-USER (setf list '(my283.jpg my23i.jpg web7-s.jpg fris88large.jpg)) def myComp (x,y): import re def getNum(str): return float(re.findall(r'\d+',str)[0]) return cmp(getNum(x),getNum(y)) CL-USER (defun my-comp (x y) (flet ((getnum (s) (parse-integer s :start (position-if #'digit-char-p s) :junk-allowed t))) ( (getnum x) (getnum y li.sort(myComp) print li # returns ['web7-s.jpg', 'my23i.jpg', 'fris88large.jpg', 'my283.jpg'] CL-USER (setf list (sort list #'my-comp)) (web7-s.jpg my23i.jpg fris88large.jpg my283.jpg) ; output li=[[2,6],[1,3],[5,4]] li.sort(key=lambda x:x[1] ) # is equivalent to the following #li.sort(lambda x, y: cmp(x[1],y[1])) print li; # prints [[1, 3], [5, 4], [2, 6]] CL-USER (setf list (sort '((2 6) (1 3) (5 4)) #' :key #'second)) ((1 3) (5 4) (2 6)) ; output Here some people might jump in and say lists might be more readable than vectors, but lists are slow. If they are slow for your data set, just use vectors instead ;) -- State, the new religion from the friendly guys who brought you fascism. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
Ville Voipio [EMAIL PROTECTED] writes: Just one thing: how reliable is the garbage collecting system? Should I try to either not produce any garbage or try to clean up manually? The GC is a simple, manually-updated reference counting system augmented with some extra contraption to resolve cyclic dependencies. It's extremely easy to make errors with the reference counts in C extensions, and either leak references (causing memory leaks) or forget to add them (causing double-free crashes). The standard libraries are pretty careful about managing references but if you're using 3rd party C modules, or writing your own, then watch out. There is no way you can avoid making garbage. Python conses everything, even integers (small positive ones are cached). But I'd say, avoid making cyclic dependencies, be very careful if you use the less popular C modules or any 3rd party ones, and stress test the hell out of your app while monitoring memory usage very carefully. If you can pound it with as much traffic in a few hours as it's likely to see in a year of deployment, without memory leaks or thread races or other errors, that's a positive sign. Well... Here the uptime benefit from using several servers is not eceonomically justifiable. I am right now at the phase of trying to minimize the downtime with given hardware resources. This is not flying; downtime does not kill anyone. I just want to avoid choosing tools which belong more to the problem than to the solution set. You're probably ok with Python in this case. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
Ville Voipio wrote: In article [EMAIL PROTECTED], Paul Rubin wrote: I would say give the app the heaviest stress testing that you can before deploying it, checking carefully for leaks and crashes. I'd say that regardless of the implementation language. Goes without saying. But I would like to be confident (or as confident as possible) that all bugs are mine. If I use plain C, I think this is the case. Of course, bad memory management in the underlying platform will wreak havoc. Python isn't perfect, but I do believe that is as good as the best of the major standard systems out there. You will have *far* greater chances of introducing errors yourself by coding in c, than you will encounter in Python. You can see the bugs fixed in recent versions, and see for yourself whether they would have crashed your system. That should be an indicator: http://www.python.org/2.4.2/NEWS.html -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list
Windows installer, different versions of Python on Windows
I would like to install several copies of Python 2.4.2 on my machine, but it doesn't seem to be possible. If I allready has a version installed, the installer only gives the options to: - change python 2.4.2 - repair python 2.4.2 - remove python 2.4.2 I would like to install different versions of Zope 3, and since it is installed under a specific python version, the simplest solution would be to install several Python versions, and install a different zope3 version under each python install. Have I misunderstood something here? -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about StringIO
Frank Millman wrote: I will try to explain my experience with popen() briefly. I have some sql scripts to create tables, indexes, procedures, etc. At present there are about 50 scripts, but this number will grow. I have been running them manually so far. Now I want to automate the process. I am supporting PostgreSQL and MS SQL Server, and the syntax is slightly different in some cases. Rather than maintain two sets of scripts, I prefix some lines with -pg- or -ms- to indicate the platform, and then use Python to parse the scripts and generate a correct output for each platform, passing it to 'psql' and 'osql' respectively, using popen(). I have had a few problems, but it would take too long to describe them all, and I just want a working solution, so I will focus on my latest attempt. I run through all the scripts and create a StringIO object with the string I want to pass. It is about 250 000 bytes long. If I run psql using popen(), and pass it the string via stdin, it works fine, but I get all the messages on the screen. If I do the same, but end the command with ' fjm 21' it works correctly and the messages end up in the file fjm, which is about 40 000 bytes long. If I run it with popen4(), it starts ok, but then hangs about 1/4 of the way through. Exactly the same happens on MSW. It seems to be hitting a limit on the size of the stdout file - is that possible? For my purposes, I will be happy to use popen() and a choice of no redirection, redirect to a file, or redirect to /dev/null. The question about popen4() is therefore academic, though I would be interested to know the answer. That's probably a deadlock as described in http://docs.python.org/lib/popen2-flow-control.html BTW, is there an equivalent of /dev/null on MSW? Dunno - but as a last resort, you could create a tempfile with a unique name (to be sure, not to override any existing data), dump your output there and later os.unlink() it... -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] try to use set. L1 = [1,1,2,3,4] L2 = [1,3, 99] A = set(L1) B = set(L2) X = A-B print X Y = B-A print Y Z = A | B print Z But how efficient is this? Could you be a bit more explicit on that point? What is the order of complexity of set([...]) or of A-B, B-A, A | B, A ^ B and A B? - The Python Documentation leaves me completely in the dark in this regard. Sorting the two lists and then extracting A-B, B-A, A|B, A B and A ^ B in one single pass seems to me very likely to be much faster for large lists. Regards, Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: socketServer questions
On Sat, 2005-10-08 at 14:09 -0700, Paul Rubinhttp: wrote: rbt [EMAIL PROTECTED] writes: Off-topic here, but you've caused me to have a thought... Can hmac be used on untrusted clients? Clients that may fall into the wrong hands? How would one handle message verification when one cannot trust the client? What is there besides hmac? Thanks, rbt I don't understand the question. HMAC requires that both ends share a secret key; does that help? That's what I don't get. If both sides have the key... how can it be 'secret'? All one would have to do is look at the code on any of the clients and they'd then know everything, right? What do you mean by verification? I'm trying to keep script kiddies from tampering with a socket server. I want the server to only load a valid or verified string into its log database and to discard everything else. Strings could come to the socket server from anywhere on the Net from any machine. This is outside my control. What is there to prevent a knowledgeable person from finding the py code on a client computer, understanding it and then being able to forge a string that the server will accept? Does that make sense? -- http://mail.python.org/mailman/listinfo/python-list
Re: socketServer questions
rbt [EMAIL PROTECTED] writes: I don't understand the question. HMAC requires that both ends share a secret key; does that help? That's what I don't get. If both sides have the key... how can it be 'secret'? All one would have to do is look at the code on any of the clients and they'd then know everything, right? Yes, clients have to keep the key secure. What do you mean by verification? I'm trying to keep script kiddies from tampering with a socket server. I want the server to only load a valid or verified string into its log database and to discard everything else. If the clients can keep a secret key secure, then use hmac. Note that if there's lots of clients, they shouldn't all use the same secret key. Instead, for client #i, let that client's key be something like hmac(your_big_secret, str(i)).digest() and the client would send #i as part of the string. You'd use #i to recompute the client's key and then use that derived key to verify the string. This is called key derivation or key diversification. If an attacker gets hold of that client's key and starts hosing you, you can disable that key without affecting the other ones. (The client is issued only the derived key and never sees the big secret). Strings could come to the socket server from anywhere on the Net from any machine. This is outside my control. What is there to prevent a knowledgeable person from finding the py code on a client computer, understanding it and then being able to forge a string that the server will accept? Yes, if you're concerned about insecure clients, you have a much more complex problem. But your x..z..y scheme is far worse than hmac. Once the attacker figures that out, there's no security at all. What is the actual application, if you can say? Depending on the environment and constraints, various approaches are possible. -- http://mail.python.org/mailman/listinfo/python-list
One last thing about SocketServer
I've read more about sockets and now, I have a better understanding of them. However, I still have a few SocketServer module questions: When used with SocketServer how exactly does socket.setdefaulttimeout() work? Does it timeout the initial connect request to the socket server or does it timeout the session between the connecting client socket and the client socket the server generated to handle the incoming request? Also, since the *only* thing a 'socket server' does is to create 'client sockets' to handle requests, how do I use socket object features on these generated clients to manage and/or monitor them? The SocketServer module is great, but it seems to hide too many details of what it's up to! Thanks, rbt -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl-Python-a-Day: Sorting
Ulrich Hobelmann wrote: Xah Lee wrote: To sort a list in Python, use the “sort” method. For example: li=[1,9,2,3]; li.sort(); print li; Likewise in Common Lisp. In Scheme there are probably packages for that as well. My apologies for not being very fluent anymore. CL-USER (setf list (sort '(1 9 2 3) #')); input (1 2 3 9); output Careful. Common Lisp's sort function is specified to be destructive, so you shouldn't use it on literal constants. So don't say (sort '(1 9 2 3) ...), say (sort (list 1 9 2 3) ...), etc. Pascal -- OOPSLA'05 tutorial on generic functions the CLOS Metaobject Protocol see http://p-cos.net/oopsla05-tutorial.html for more details -- http://mail.python.org/mailman/listinfo/python-list
Re: Merging sorted lists/iterators/generators into one stream of values...
Alex Martelli [EMAIL PROTECTED] wrote: George Sakkis [EMAIL PROTECTED] wrote: ... manipulation of a heap to place an item in the right spot, but with 4-5 or a few more sources might not make an impact at all. Unless you're talking about hundreds or thousands sources, it probably won't. I would still go for the heap solution since IMO the resulting code it's more readable and easier to understand. I'm not so sure about either sentence...: Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100 --how=S Best time for 10 loops: 0.247116088867 Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100 --how=H Best time for 10 loops: 0.10344004631 i.e., a heap solution may be over 4 times faster than a sort-based one (in the following implementations). Interesting; I thought timsort on small almost ordered lists would be practically as fast as the heap. Still, how is 0.10344 over 4 times faster than 0.247116 ? Readability seems quite comparable (skipping the rest of the infrastructure, which generates random sorted streams and ensures a stream is exhausted and verifies it etc etc): def merge_by_sort(streams): sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] while sources: sources.sort(reverse=True) best_source = sources[-1] yield best_source[0] try: best_source[0] = best_source[-1]() except StopIteration: sources.pop() def merge_by_heap(streams): sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] heapq.heapify(sources) while sources: best_source = sources[0] yield best_source[0] try: best_source[0] = best_source[-1]() except StopIteration: heapq.heappop(sources) else: heapq.heapreplace(sources, best_source) Indeed, these are almost equivalent as far as readability goes; the previous examples in the thread were less clear. By the way, why do you need 'i' and enumerate above ? Hmmm, I wonder if something like merge_by_heap would be a good candidate for itertool. Raymond...? Alex Yes, it would be nice to make it into 2.5. George -- http://mail.python.org/mailman/listinfo/python-list
Re: Merging sorted lists/iterators/generators into one stream of values...
Alex Martelli wrote: George Sakkis [EMAIL PROTECTED] wrote: ... manipulation of a heap to place an item in the right spot, but with 4-5 or a few more sources might not make an impact at all. Unless you're talking about hundreds or thousands sources, it probably won't. I would still go for the heap solution since IMO the resulting code it's more readable and easier to understand. ... i.e., a heap solution may be over 4 times faster than a sort-based one (in the following implementations). Readability seems quite comparable (skipping the rest of the infrastructure, which generates random sorted streams and ensures a stream is exhausted and verifies it etc etc): One thing to keep in mind (if you care about performance) is that you one could use bisect, instead of sort, as the sorted list of streams is already in order save for the one element you are processing. Btw, nice trick with reverse to reduce memory copying, when did that get introduced? Wonder if bisect can deal with reverse-sorted elements. Anyway, should reduce the O-complexity of that part of the operation, though you'll still have to do a memcpy to shift the rest of the source list's array, and if it can't deal with reverse-sorted lists it would move you back to front-of-list popping. Oh, we're still missing use of a comparison function in both versions. I'd think you'd want that functionality *available* if you're going to make this a general tool. You'll also need to check for StopIteration on creation of sources for null sequences. Finally, why the 'i' element? It's never used AFAICS. def merge_by_sort(streams): sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] while sources: sources.sort(reverse=True) best_source = sources[-1] yield best_source[0] try: best_source[0] = best_source[-1]() except StopIteration: sources.pop() ... Have fun, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-list
Unlimited Free Music Downloads !
Download Unlimited Free Music Click Here! -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows installer, different versions of Python on Windows
When you install Python it plug entries into the registry, so that when you go to install add-ons that are pre-compiled binaries, they look into the registry for the python directory. If you can find out how to manipulate the registry so that the binaries would recognize different installations, you'd be good to go. This would probably involve having copies of the same key with different values. I would like to install several copies of Python 2.4.2 on my machine, but it doesn't seem to be possible. If I allready has a version installed, the installer only gives the options to: - change python 2.4.2 - repair python 2.4.2 - remove python 2.4.2 I would like to install different versions of Zope 3, and since it is installed under a specific python version, the simplest solution would be to install several Python versions, and install a different zope3 version under each python install. Have I misunderstood something here? == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups == Get Anonymous, Uncensored, Access to West and East Coast Server Farms! == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM == -- http://mail.python.org/mailman/listinfo/python-list
Re: best Pythonic way to do this sort: Python newb
Satchidanand Haridas [EMAIL PROTECTED] wrote: So, I want to sort myList by the return of myFunction( value3 ) I tried doing the following... with no luck so far myList.sort(lambda x, y: cmp(myFunction(x[2]), myFunction(y[2])) I think the above statement should be as follows: myList.sort(lambda x, y: cmp(myFunction(x[2]) - myFunction(y[2])) hope that helps. It would help more if you tested it before you posted. cmp takes two arguments (let alone that subtraction may not be defined for the list elements), so the original version is correct. George -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
Daniel Delay wrote: I agree the comparison to the mathematical o-operator is misleading, it was just to say sometimes, it can be usefull introduce new syntax to avoid too many nested parenthesis To replace them by the same amount of parentheses with a dot in front? Not very convincing. This is usefull when you need to compose few already defined functions, but I more often have to compose few expressions, which is the goal of my proposition. The only reason this _could_ be preferable was in a situation where one large expression contains several subexpressions that are supposed to be the same value. Like this: foo.join(bar.split()+ bar.split()) Then your prosal would make it bar.split().(foo.join(? + ?)) But then again, this is by no means better to read. The only justification is that you want to avoid the possibly costly double evaluation of the common subexpression. But then, the critic of e.g. Frederik applies: Why don't you do a = bar.split() foo.join(a + a) Beats everything else in readability. In fact it has nothing to do with magical expression : this will represent the value of the current expression you work on, in the same way self represent the value of the object you work on. I very well understand that. But I think the only thing it leads to is more convoluted code. Which one wants to avoid. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: One last thing about SocketServer
rbt wrote: I've read more about sockets and now, I have a better understanding of them. However, I still have a few SocketServer module questions: When used with SocketServer how exactly does socket.setdefaulttimeout() work? Does it timeout the initial connect request to the socket server or does it timeout the session between the connecting client socket and the client socket the server generated to handle the incoming request? setdefaulttimeout() simply sets the default timeout for all sockets created thereafter. This timeout applies to any socket operation, I believe (though I am unsure about accept()). Also, since the *only* thing a 'socket server' does is to create 'client sockets' to handle requests, how do I use socket object features on these generated clients to manage and/or monitor them? When the accept() call on a socket returns a tuple(socket, address): the first element of the returned tuple is the socket you use to communicate with that particular client (in other words, it represents the server end of the connection that's just been accept()ed). So you can read and write that socket to communicate with that client over that specific connection. Of course, if you don't use either the ThreadingMixIn or the ForkingMixIn then communication with one client will effectively stop you form accept()ing any more connections, hence the need for the mix-in classes. The SocketServer module is great, but it seems to hide too many details of what it's up to! Well, of course, that is what abstractions are for! You should bear in mind that SocketServer isn't necessarily the most efficient or effective way to handle multiple clients concurrently, but it's very convenient when you are just getting started. Later you might want to consider an asyncore-based approach, or perhaps using the Twisted package. Both of these solutions are a little more robust for production code. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.perl.misc John Bokma [EMAIL PROTECTED] wrote: Roedy Green [EMAIL PROTECTED] wrote: On 8 Oct 2005 23:39:27 GMT, John Bokma [EMAIL PROTECTED] wrote or quoted : Yeah, yeah, and 640K is enough for everybody. Same song, different tune. For how long. Surely attachments are a stop gap. Can you imagine people sharing images that way 100 years from now? No, but I agree with you :-) I am not using HTML myself in email, but I will when it makes things easier. Why should we wait for the future? The problems blocking easy to use photo sharing are not technological but social. Yup, agreed. Like I already wrote, if I route all HTML email to /dev/null I'll lose some customers, and some friends :-) What I find is that when I see emails which are obviously spam, I simply do not read them and delete them immediately. But then I use Pine rather than a web browser... and while some forms of HTML may be rendered, nothing is automatically pulled down. Axel -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.perl.misc Tim Tyler [EMAIL PROTECTED] wrote: In comp.lang.java.programmer Steven D'Aprano [EMAIL PROTECTED] wrote or quoted: Only if your photos are so obscure and confusing that they need captions. Here's Johnny with the dog. Here is Johnny with the dog again. This one is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog again -- that's the dog on the left, in case it isn't clear. Just for a change, this is Johnny wearing a hat. It is blue with a feather in it, in case you couldn't tell from, oh I don't know, looking at the actual picture. What have you got against captions? Giving photos captions is a *very* common practice. Why not just put them on a web page? It is then possible to include thumbnails so the recipient can chose to see which ones he cares to look at in detail. It also allows the web address to be sent to several people without wasting bandwith. Axel -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
Christian Stapfer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: try to use set. Sorting the two lists and then extracting A-B, B-A, A|B, A B and A ^ B in one single pass seems to me very likely to be much faster for large lists. Why don't you implement it, test it and time it to be more convincing about your intuition ? George -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
On Wed, 05 Oct 2005 21:36:47 -0600, rumours say that Mahesh Padmanabhan [EMAIL PROTECTED] might have written: In article [EMAIL PROTECTED], Xah Lee [EMAIL PROTECTED] wrote: snip lot of drivel While I don't like to feed the trolls, I do find his posts amusing. He is like a spoilt child seeking attention. s/is like/is/ -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
Re: socketServer questions
On Mon, 2005-10-10 at 05:54 -0700, Paul Rubinhttp: wrote: rbt [EMAIL PROTECTED] writes: I don't understand the question. HMAC requires that both ends share a secret key; does that help? That's what I don't get. If both sides have the key... how can it be 'secret'? All one would have to do is look at the code on any of the clients and they'd then know everything, right? Yes, clients have to keep the key secure. What do you mean by verification? I'm trying to keep script kiddies from tampering with a socket server. I want the server to only load a valid or verified string into its log database and to discard everything else. If the clients can keep a secret key secure, then use hmac. Note that if there's lots of clients, they shouldn't all use the same secret key. Instead, for client #i, let that client's key be something like hmac(your_big_secret, str(i)).digest() and the client would send #i as part of the string. How is this different from sending a pre-defined string from the client that the server knows the md5 hash of? The clients know the string, the server knows the hash of that string. Also, could this not be done both ways? So that, if an attacker figures out the string he's supposed to send from a client to the server (which he could easily do). He could not easily figure out the string the server should send back as all he would have is the hash of that string. So, before the actual data is sent from the client to the server. The client would send it's secret string that the server would verify and then if that worked, the server would send its own secret string that the client must verify. We'd have two secret strings instead of one. You'd use #i to recompute the client's key and then use that derived key to verify the string. This is called key derivation or key diversification. If an attacker gets hold of that client's key and starts hosing you, you can disable that key without affecting the other ones. (The client is issued only the derived key and never sees the big secret). This is interesting. I didn't know that was possible. Strings could come to the socket server from anywhere on the Net from any machine. This is outside my control. What is there to prevent a knowledgeable person from finding the py code on a client computer, understanding it and then being able to forge a string that the server will accept? Yes, if you're concerned about insecure clients, you have a much more complex problem. But your x..z..y scheme is far worse than hmac. Once the attacker figures that out, there's no security at all. I dropped the x,y,z scheme after your first response ;) What is the actual application, if you can say? Depending on the environment and constraints, various approaches are possible. Nothing important. It just logs network data. It's an anti-theft program for laptops that phones home data like this: public and private IP(s), MAC addy, date, time, etc. Maybe I'm putting too much thought into it. Python encourages good design and I try to follow that encouragement when coding... even for trivial things such as this. -- http://mail.python.org/mailman/listinfo/python-list
TurboGears slashdotted
TurboGears: Python on Rails? post: http://developers.slashdot.org/developers/05/10/10/0650207.shtml?tid=156 -- http://mail.python.org/mailman/listinfo/python-list
Re: Merging sorted lists/iterators/generators into one stream of values...
George Sakkis [EMAIL PROTECTED] wrote: ... i.e., a heap solution may be over 4 times faster than a sort-based one (in the following implementations). Interesting; I thought timsort on small almost ordered lists would be practically as fast as the heap. Still, how is 0.10344 over 4 times faster than 0.247116 ? Oops, 2.5 times (for 10 streams) -- the ratio keeps getting bigger with the number of streams, the figure 4 I had in mind was probably from comparisons with 50 streams or so. timsort needs N comparisons even if the list is already ordered (just to check it is) while heaps can do with log(N) comparisons or even less in the best case -- that's the key issue here. sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] ... Indeed, these are almost equivalent as far as readability goes; the previous examples in the thread were less clear. By the way, why do you need 'i' and enumerate above ? Making sure that, if the first items are identical, the sorting (or comparison for heap) does not compare the _methods_ -- no big deal if it does, but that doesn't logically make sense. If we had key= arguments, that would ENSURE no such comparison, but heaps didn't support that in 2.4 and I wanted to keep the playing field level, so I used the above old trick to ensure stable sorting without comparisons beyond a given field (more details were explained in the 1st edition of the Cookbook, but I hope I give the general idea). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Merging sorted lists/iterators/generators into one stream of values...
Mike C. Fletcher [EMAIL PROTECTED] wrote: ... One thing to keep in mind (if you care about performance) is that you one could use bisect, instead of sort, as the sorted list of streams is already in order save for the one element you are processing. Btw, nice trick with reverse to reduce memory copying, when did that get introduced? Python 2.4 Wonder if bisect can deal with reverse-sorted elements. Not AFAIK. Anyway, should reduce the O-complexity of that part of the operation, though you'll still have to do a memcpy to shift the rest of the source list's array, and if it can't deal with reverse-sorted lists it would move you back to front-of-list popping. Yeah, if you have to pop the front you're O(N) anyway, which is basically what timsort does with nearly-ordered lists (though timsort uses O(N) _comparisons_ while bisecting would use O(N) _moves_). Oh, we're still missing use of a comparison function in both versions. Trivial, just have the functions accept a key= and use that to prepare the auxiliary list they're using anyway. I'd think you'd want that functionality *available* if you're going to make this a general tool. You'll also need to check for StopIteration on creation of sources for null sequences. True, the functions as prepared don't accept empty streams (exactly because they don't specialcase StopIteration on the first calls to next). Pretty trivial to remedy, of course. Finally, why the 'i' element? It's never used AFAICS. It's used by the list's lexicographic comparison when the first elements of two lists being compared are equal (which can happen, of course) to avoid comparing the last elements (which are methods... no big deal if they get compared, but it makes no logical sense). So, an example enhanced merge_by_sort: def merge_by_sort(streams, key=None): if not key: key = lambda x: x sources = [] for i, s in enumerate(streams): try: first_item = s.next() except StopIteration: pass else: sources.append((key(item), i, item, s.next)) while sources: sources.sort(reverse=True) best_source = sources[-1] yield best_source[2] try: best_source[2] = best_source[-1]() except StopIteration: sources.pop() else: best_source[0] = key(best_source[2]) Of course, since the sort method DOES accept a key= parameter, this could be simplified, but I'll leave it like this to make it trivial to see how to recode the merging by heap as well (in 2.4)... Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
On Mon, 10 Oct 2005 14:34:35 +0200, Christian Stapfer wrote: Sorting the two lists and then extracting A-B, B-A, A|B, A B and A ^ B in one single pass seems to me very likely to be much faster for large lists. Unless you are running a Python compiler in your head, chances are your intuition has no connection to the actual performance of Python except by pure coincidence. Write some code, and time it in action. In fact, here is some code I've written for you, complete with timer. Do yourself a favour, and run it and see for yourself which is faster. Then, if you think you can write a list version that is more efficient than my (admittedly very inefficient) version, please do so. Then time the difference again. Then think about how much time it took you to write, test and debug your list version, compared to my four lines using sets. from sets import Set import time def compare_and_separate(A, B): only_A = [] only_B = [] both_AB = [] for item in A: # ignore items we've already seen before if item in only_A or item in both_AB: continue if item in B: both_AB.append(item) else: only_A.append(item) for item in B: # ignore items we've already seen before if item in only_B or item in both_AB: continue only_B.append(item) return (only_A, only_B, both_AB) def compare_and_separate_with_sets(A, B): only_A = list(Set(A)-Set(B)) only_B = list(Set(B)-Set(A)) both_AB = list(Set(A+B) - Set(only_A+only_B)) return (only_A, only_B, both_AB) A = range(199) + range(44, 300, 3) + range(250, 500) + range(2000, 2100) B = range(1000) + range(3000, 4000) def tester(): # confirm that the two functions give the same results r1 = compare_and_separate(range(5), range(3,8)) r2 = compare_and_separate_with_sets(range(5), range(3,8)) print r1 print r2 if r1 == r2: print Same. else: print Warning: results are different. loopit = range(20) # repeat the test 20 times for timing purposes t1 = time.time() for i in loopit: results = compare_and_separate(A, B) t1 = time.time() - t1 t2 = time.time() for i in loopit: results = compare_and_separate_with_sets(A, B) t2 = time.time() - t2 print Time with loops:, t1 print Time with sets:, t2 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: socketServer questions
rbt [EMAIL PROTECTED] writes: Instead, for client #i, let that client's key be something like hmac(your_big_secret, str(i)).digest() and the client would send #i as part of the string. How is this different from sending a pre-defined string from the client that the server knows the md5 hash of? The clients know the string, the server knows the hash of that string. I'm confused, I don't understand what that md5 whatever would do for you. I'm assuming the server is secure and the clients are less secure. Also, could this not be done both ways? So that, if an attacker figures out the string he's supposed to send from a client to the server (which he could easily do). He could not easily figure out the string the server should send back as all he would have is the hash of that string. I'm still confused, are you now trying to prevent the client from accepting bogus stuff from the server? You can do that with a digital signature and not need client-side secrets. But I still don't see much gain from that. So, before the actual data is sent from the client to the server. The client would send it's secret string that the server would verify and then if that worked, the server would send its own secret string that the client must verify. We'd have two secret strings instead of one. If the client is insecure, an attacker who gets control of it will get all the secrets in it, so it doesn't matter if there's one or several. Nothing important. It just logs network data. It's an anti-theft program for laptops that phones home data like this: public and private IP(s), Yeah, if a laptop is stolen and the thief is sophisticated enough to go finding the authentication keys inside some binary, s/he also won't be dumb enough to leave the program active. Those programs are just for dumb thieves (of whom there are a lot) or their customers, who simply plug in the laptop and start using it, without concern about what software is on it. If they have any sense they'll do a total reinstall. But anyway, yeah, people who enroll in the system should get a customer number. Then you can derive an auth key from the customer number as described earlier. -- http://mail.python.org/mailman/listinfo/python-list
Default argument to __init__
Hi All: Here's a piece of Python code and it's output. The output that Python shows is not as per my expectation. Hope someone can explain to me this behaviour: [code] class MyClass: def __init__(self, myarr=[]): self.myarr = myarr myobj1 = MyClass() myobj2 = MyClass() myobj1.myarr += [1,2,3] myobj2.myarr += [4,5,6] print myobj1.myarr print myobj2.myarr [/code] The output is: [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] Why do myobj1.myarr and myobj2.myarr point to the same list? The default value to __init__ for the myarr argument is [], so I expect that every time an object of MyClass is created, a new empty list is created and assigned to myarr, but it seems that the same empty list object is assigned to myarr on every invocation of MyClass.__init__ It this behaviour by design? If so, what is the reason, as the behaviour I expect seems pretty logical. Thanks. Vaibhav -- http://mail.python.org/mailman/listinfo/python-list
Re: socketServer questions
On Mon, 2005-10-10 at 07:46 -0700, Paul Rubinhttp: wrote: rbt [EMAIL PROTECTED] writes: Instead, for client #i, let that client's key be something like hmac(your_big_secret, str(i)).digest() and the client would send #i as part of the string. How is this different from sending a pre-defined string from the client that the server knows the md5 hash of? The clients know the string, the server knows the hash of that string. I'm confused, I don't understand what that md5 whatever would do for you. I'm assuming the server is secure and the clients are less secure. Also, could this not be done both ways? So that, if an attacker figures out the string he's supposed to send from a client to the server (which he could easily do). He could not easily figure out the string the server should send back as all he would have is the hash of that string. I'm still confused OK, we'll leave it at that and just accept that we're from different planets ;) Thanks for the help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
request for Google groups enhancement: Report Abuse button should have 4 choices: - Spam - Illegal Content - Xah - other ;-} Christos Georgiou wrote: On Wed, 05 Oct 2005 21:36:47 -0600, rumours say that Mahesh Padmanabhan [EMAIL PROTECTED] might have written: In article [EMAIL PROTECTED], Xah Lee [EMAIL PROTECTED] wrote: snip lot of drivel While I don't like to feed the trolls, I do find his posts amusing. He is like a spoilt child seeking attention. s/is like/is/ -- TZOTZIOY, I speak England very best. Dear Paul, please stop spamming us. The Corinthians -- http://mail.python.org/mailman/listinfo/python-list
subprocess and non-blocking IO (again)
I am trying to rewrite a PERL automation which started a monitoring application on many machines, via RSH, and then multiplexed their collective outputs to stdout. In production there are lots of these subprocesses but here is a simplified example what I have so far (python n00b alert!) - SNIP - import subprocess,select,sys speakers=[] lProc=[] for machine in ['box1','box2','box3']: p = subprocess.Popen( ('echo '+machine+';sleep 2;echo goodbye;sleep 2;echo cruel;sleep 2;echo world'), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=None, universal_newlines=True ) lProc.append( p ) speakers.append( p.stdout ) while speakers: speaking = select.select( speakers, [], [], 1000 )[0] for speaker in speaking: speech = speaker.readlines() if speech: for sentence in speech: print sentence.rstrip('\n') sys.stdout.flush() # sanity check else: # EOF speakers.remove( speaker ) - SNIP - The problem with the above is that the subprocess buffers all its output when used like this and, hence, this automation is not informing me of much :) In PERL, realtime feedback was provided by setting the following: $p-stdout-blocking(0); How do I achieve this in Python ? This topic seems to have come up more than once. I am hoping that things have moved on from posts like this: http://groups.google.com/group/comp.lang.python/browse_thread/thread/5472ce95eb430002/434fa9b471009ab2?q=blockingrnum=4#434fa9b471009ab2 as I don't really want to have to write all that ugly fork/dup/fcntl/exec code to achieve this when high-level libraries like subprocess really should have corresponding methods. If it makes anything simpler, I only *need* this on Linux/Unix (Windows would be a nice extra though). thanks for reading, Marc -- http://mail.python.org/mailman/listinfo/python-list
read serial data from a barcode reader/scanner using python
Hi. is therea way to program python to read serial data from a barcode reader/scanner and then using the parallel port of the PC to activatean electromagnetic door lock. edgar -- http://mail.python.org/mailman/listinfo/python-list
Send password over TCP connection
Hi all, I have a program that serves client programs. The server has a login password, which has to be used by each client for logging in. So, when the client connects, it sends a string with a password, which is then validated on the server side. The problem is obvious: anyone can get the password just sniffing the network. How can I solve this? Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Send password over TCP connection
dcrespo [EMAIL PROTECTED] writes: I have a program that serves client programs. The server has a login password, which has to be used by each client for logging in. So, when the client connects, it sends a string with a password, which is then validated on the server side. The problem is obvious: anyone can get the password just sniffing the network. How can I solve this? If you really want to do it right, use SRP, http://srp.stanford.edu. -- http://mail.python.org/mailman/listinfo/python-list
Confused on Kid
Hey, so I heard about the TurboGears posting and decided to investigate. I watched some of their video on building a wiki in 20 minutes and was totally blown away because I'm used to python...straight python, not melding together 4 different APIs into one to blah blah. ANYWAY. I was investigating each subproject individually and could not, for the life of me figure out how Kid worked. I understand that it takes a well-formed XML document and transforms it, but I could not figure out where it transforms it, or how to transform a document. They have plenty of template examples, but I'm left say, What do I do with this? I know I can't just pop in it a browser because it has no sort of style sheet or anything so it would just render as an XML document. What do you do after you have a kid template? == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups == Get Anonymous, Uncensored, Access to West and East Coast Server Farms! == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM == -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
George Sakkis [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Christian Stapfer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: try to use set. Sorting the two lists and then extracting A-B, B-A, A|B, A B and A ^ B in one single pass seems to me very likely to be much faster for large lists. Why don't you implement it, test it and time it to be more convincing about your intuition ? The problem is in the generation of the test data. Even merely generating a set of (suitably average, random, and suitably worst case) datasets might turn out to be a major undertaking. If the documentation stated the order-of-magnitude behavior of those basic operations up front, then I (and *anyone* else who ever wanted to use those operations on large lists / large sets) could do a quick order-of-magnitude estimation of how a certain program design will behave, performance wise. *Experimenting* is not necessarily as easy to do as you seem to believe. How do you, for example, hit upon the worst-case behavior with your test data? - Without knowing *anything* about the implementation it might a matter sheer luck. If you *know* something about the implementation then, of course, you might be able to figure it out. (But note that if you know *that* much about the implementation, you usually have an order-of- magnitude estimate anyway and don't need to do *any* experimenting in order to answer my question.) Regards, Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a Britishaccent...
Duncan Smith wrote: Steve Holden wrote: There are special rules for the monarchs, who are expected to refer to themselves in the first person plural. Yes, although I'm not actually sure where the 'royal we' comes from; I was under the (probably misinformed) impression that since the King/Queen is the representative of the entire nation, they use the first person plural, because when they speak they speak for the all the (multiple) people in the land. I'm unaware of what term a monarch uses in a private, rather than public, context. (Never having had the opportunity to drink a pint with Lizzie, Chuck, and Cammie. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Send password over TCP connection
simplest approach is to 1 way hash the password ... perhaps using md5 normally with passwords the server only has to check if it is the same word, assuming the same hash algorithms the same hash value can be created at client. Its not hugely secure ... anyone sniffing can grab your hash value and then try to crack it at their leisure. It would be better to communicate over ssl. Anyone know of a simple ssl api in python :-) dcrespo wrote: Hi all, I have a program that serves client programs. The server has a login password, which has to be used by each client for logging in. So, when the client connects, it sends a string with a password, which is then validated on the server side. The problem is obvious: anyone can get the password just sniffing the network. How can I solve this? Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Default argument to __init__
vaibhav Here's a piece of Python code and it's output. The output that vaibhav Python shows is not as per my expectation. Hope someone can vaibhav explain to me this behaviour: ... Yes, your default arg is evaluated once, at method definition time and shared betwee all instances of MyClass. See the thread last week on the same thing for more detail. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Default argument to __init__
[EMAIL PROTECTED] wrote: Hi All: Here's a piece of Python code and it's output. The output that Python shows is not as per my expectation. Hope someone can explain to me this behaviour: [code] class MyClass: def __init__(self, myarr=[]): self.myarr = myarr myobj1 = MyClass() myobj2 = MyClass() myobj1.myarr += [1,2,3] myobj2.myarr += [4,5,6] print myobj1.myarr print myobj2.myarr [/code] The output is: [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] Why do myobj1.myarr and myobj2.myarr point to the same list? The default value to __init__ for the myarr argument is [], so I expect that every time an object of MyClass is created, a new empty list is created and assigned to myarr, but it seems that the same empty list object is assigned to myarr on every invocation of MyClass.__init__ It this behaviour by design? If so, what is the reason, as the behaviour I expect seems pretty logical. The default value of the keyword argument is evaluated once, at function declaration time. The idiom usually used to avoid this gotcha is: def __init__(self, myarr=None): if myarr is None: myarr = [] This ensures each call with the default myarr gets its own list. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Default argument to __init__
This comes up on the list about once a week on this list. See: http://www.nexedi.org/sections/education/python/tips_and_tricks/python_and_mutable_n/view -Larry Bates [EMAIL PROTECTED] wrote: Hi All: Here's a piece of Python code and it's output. The output that Python shows is not as per my expectation. Hope someone can explain to me this behaviour: [code] class MyClass: def __init__(self, myarr=[]): self.myarr = myarr myobj1 = MyClass() myobj2 = MyClass() myobj1.myarr += [1,2,3] myobj2.myarr += [4,5,6] print myobj1.myarr print myobj2.myarr [/code] The output is: [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] Why do myobj1.myarr and myobj2.myarr point to the same list? The default value to __init__ for the myarr argument is [], so I expect that every time an object of MyClass is created, a new empty list is created and assigned to myarr, but it seems that the same empty list object is assigned to myarr on every invocation of MyClass.__init__ It this behaviour by design? If so, what is the reason, as the behaviour I expect seems pretty logical. Thanks. Vaibhav -- http://mail.python.org/mailman/listinfo/python-list
Re: Confused on Kid
Brandon K wrote: Hey, so I heard about the TurboGears posting and decided to investigate. I watched some of their video on building a wiki in 20 minutes and was totally blown away because I'm used to python...straight python, not melding together 4 different APIs into one to blah blah. ANYWAY. I was investigating each subproject individually and could not, for the life of me figure out how Kid worked. I understand that it takes a well-formed XML document and transforms it, but I could not figure out where it transforms it, or how to transform a document. They have plenty of template examples, but I'm left say, What do I do with this? I know I can't just pop in it a browser because it has no sort of style sheet or anything so it would just render as an XML document. What do you do after you have a kid template? Did you read the documentation? http://kid.lesscode.org/guide.html -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
Christian Stapfer wrote: George Sakkis [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Christian Stapfer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: try to use set. Sorting the two lists and then extracting A-B, B-A, A|B, A B and A ^ B in one single pass seems to me very likely to be much faster for large lists. Why don't you implement it, test it and time it to be more convincing about your intuition ? The problem is in the generation of the test data. Even merely generating a set of (suitably average, random, and suitably worst case) datasets might turn out to be a major undertaking. If the documentation stated the order-of-magnitude behavior of those basic operations up front, then I (and *anyone* else who ever wanted to use those operations on large lists / large sets) could do a quick order-of-magnitude estimation of how a certain program design will behave, performance wise. *Experimenting* is not necessarily as easy to do as you seem to believe. How do you, for example, hit upon the worst-case behavior with your test data? - Without knowing *anything* about the implementation it might a matter sheer luck. If you *know* something about the implementation then, of course, you might be able to figure it out. (But note that if you know *that* much about the implementation, you usually have an order-of- magnitude estimate anyway and don't need to do *any* experimenting in order to answer my question.) You are, of course, either assuming that there's a single implementation of Python, or that all implementations have the same behaviour. Or alternatively you are asking all implementers to do what you seem to consider so difficult (i.e. identify worst-case scenarios and then estimate order-of-magnitude behaviour for them). Test results with known test data are relatively easy to extrapolate from, and if your test data are reasonably representative of live data then so will your performance estimates. Anyway, aren't you more interested in average behaviour than worst-case? Most people are. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Send password over TCP connection
Peter Tillotson wrote: simplest approach is to 1 way hash the password ... perhaps using md5 No, it isn't - see below. normally with passwords the server only has to check if it is the same word, assuming the same hash algorithms the same hash value can be created at client. Unfortunately this means that the client sends the same string every time the user authenticates. Its not hugely secure ... anyone sniffing can grab your hash value and then try to crack it at their leisure. It would be better to communicate over ssl. It's not even that secure: all they have to do is replay the data sniffed from the server and they too can authenticate themselves. They don't have to know what the plain-text password is. Anyone know of a simple ssl api in python :-) A safer way would be to use some sort of challenge-response mechanism, where the server presents a challenge C to the client, which then computes some function of both C and the plain-text password provided by the user. The server then authenticates by performing the same computation on C and the known password. As long as the server uses a different challenge each time then this is at least secure from replay attacks. But this scheme does have the weakness that the server must know the password of each user. For something even more secure, look at OPIE and similar schemes. But let's not forget that all these schemes only secure the authentication exchange: they do nothing to protect application data. regards Steve dcrespo wrote: Hi all, I have a program that serves client programs. The server has a login password, which has to be used by each client for logging in. So, when the client connects, it sends a string with a password, which is then validated on the server side. The problem is obvious: anyone can get the password just sniffing the network. How can I solve this? Daniel -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Send password over TCP connection
Anyone know of a simple ssl api in python :-) Perhaps pow may help: http://sourceforge.net/projects/pow or pyopenssl: http://pyopenssl.sourceforge.net/ Regards, Josef -- http://mail.python.org/mailman/listinfo/python-list
unable to import os
Fredrik Lundh,I replaced mtime = os.stat(Path + file_name)[os.path.stat.ST_MTIME] with mtime = nt.stat("q.py") per your suggested, then ran it from IDLE 2.4.2. Here is the message I got, Traceback (most recent call last): File "C:\Documents and Settings\nguyeki\Desktop\Oct7", line 37, in -toplevel- main() File "C:\Documents and Settings\nguyeki\Desktop\Oct7", line 17, in main mtime = nt.stat("q.py") OSError: [Errno 2] No such file or directory: 'q.py' I did the search and could not find the file "q.py". -- http://mail.python.org/mailman/listinfo/python-list
Re: Python reliability
You might try a take over mode -- starting another copy gets to the point it looks to listen for UDP, the (if the listening fails), tells the other process to die over UDP, taking over then. This scheme would would reduce your time-to-switch to a much shorter window. Whenever given the shutdown signal, you could turn on the watcher sleeping light. The remaining issue, replacing hardware or OS (possibly due to failure) probably changes the UDP address. That might be trickier. I certainly feel happier when I can do a hand-off to another box, but it sounds like you might need the instruments to broadcast or multicast to get to that happy place. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list