From rantingrick at gmail.com Tue Feb 1 00:13:06 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 31 Jan 2011 21:13:06 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: On Jan 31, 4:17?pm, Kevin Walzer wrote: > Rick, > > I've spent a fair amount of time in the IDLE source tree, putting > together patches for various Mac-specific bugs and submitting them to > the Python tracker, and I agree the code is crufty and disorganized. It > is certainly not an example of current best practices in Tkinter > development. The code base has accrued over the years, has been touched > by many, many different hands, and I think its current messy state > reflects that legacy. Thanks for admitting this. Some people refuse to see the truth! > But, as I understand it, the purpose of IDLE is not to provide a > pedagogical example of Tkinter programming practices, but instead to > provide a lightweight development environment for those learning Python, > to interactively explore different aspects of Python. For this it serves > its purpose well. I use IDLE a good deal for my Python development work, > and the cruftiness of the code under the hood is not an impediment to me > getting my work done (unless the work is patching IDLE itself). Yes. IDLE is first and foremost a tool to get work done. However we should not ignore the fact that IDLE could also be a great learning resource for Tkinter GUI's and other subjects. Why not clean up the code base? We could start small. First, move the custom widgets like textView, Tabbedpages, FindDialog, ReplaceDialog, and TreeWidget into the lib-tk for others to use more freely. Then we can modify the "event robbers" CallTips, ParenMatch, and ColorDelegator. Just small steps Kevin. It all starts with babysteps. At least we would be doing something. Currently we are sitting around waiting for a miracle to happen, and problems are solved by methods, not miracles! > Given this, I don't see any huge need to bulldoze IDLE to the ground and > replace it with something else, or even do massive rewrites of the code, > unless such a project also significantly improved the user-facing > portions of IDLE as well. Well some changes and improvements can be made to the UI as well. From rajendra4linux at gmail.com Tue Feb 1 00:16:48 2011 From: rajendra4linux at gmail.com (Rajendra prasad Gottipati) Date: Mon, 31 Jan 2011 21:16:48 -0800 Subject: how to modify axis tick values exponential value location in matplotlib In-Reply-To: References: Message-ID: not able to change the location of exponent/offset label in the axis, in case of multiple y axis exponent/offset label of one axis is overwriting other axis value, how to control the location of this lable(like 1e8).Can anybody help me solving this issue. On Sun, Jan 30, 2011 at 9:55 AM, Rajendra prasad Gottipati < rajendra4linux at gmail.com> wrote: > it seems relevant to my issue. > > > http://stackoverflow.com/questions/3677368/matplotlib-format-axis-offset-values-to-whole-numbers-or-specific-number > > > On Sun, Jan 30, 2011 at 9:45 AM, Rajendra prasad Gottipati < > rajendra4linux at gmail.com> wrote: > >> Hi, >> >> I am plotting the graph for long values like(267838484) so that its >> printing the tick lables on axes as 2.6 , 2.8 and at the top its having a >> text like e07 something like this, I want to move the display location of >> this exponent (e07) as i am having trouble in having multiple y-axis as they >> are getting mixed in text. like (e07 is written on top of e08 of other axis) >> >> Can any one help me in getting this done? also i am having issue in >> getting tick lables of x-axis while plotting with pylab.plot_date. >> >> >> Regards >> Raja >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Feb 1 00:26:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 31 Jan 2011 21:26:53 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: On Jan 31, 4:38?pm, Robert wrote: > I think it would be interesting as well. Hmmmm, I am about to do the > O'Reilly series that Steve Holden did for Python. Did you see the video Steve Holden did with Trish Gray? Just for fun fast forward to 0:03:30. Just as Trish comments about Python diversity Steve gets all shook up... man you could cut the tension with a knife!!! http://www.oreillyschool.com/courses/python1/ Oh, and Trish, if you are out there and you would like a "personal" introduction to Python programming i would be very happy to give you some very, very, private lessons using my python... . . . . . ....interpretor. *wink* ;-) From rantingrick at gmail.com Tue Feb 1 00:37:58 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 31 Jan 2011 21:37:58 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <48d40a1b-9bfc-47aa-b06c-9889273d835d@o32g2000prb.googlegroups.com> Message-ID: On Jan 31, 9:24?pm, Giampaolo Rodol? wrote: > Actually I don't even understand how can IDLE source code quality have > anything to do with python success or future adoption, as you implied > in your statements. Well thats because you are not looking at this from the correct perspective. Every piece of code, every module, every documentation, every community grudge reflects on us in positive and negative ways. And the IDLE library is reflecting pretty badly on us. The IDLE library is making us look like a bunch of two bit script kiddies who cannot even follow our own philosophies. From me+list/python at ixokai.io Tue Feb 1 01:10:34 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 31 Jan 2011 22:10:34 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: <4D47A3DA.70708@ixokai.io> On 1/31/11 9:26 PM, rantingrick wrote: > Oh, and Trish, if you are out there and you would like a "personal" > introduction to Python programming i would be very happy to give you > some very, very, private lessons using my python... > . > . > . > . > . > ....interpretor. *wink* > > ;-) You are disgusting. If Trish Gray were here, I'd offer a sincere apology on behalf of the community for you. Which is ironic, considering how one of my major complaints about you is your audacity to claim to speak for "We", "The Community". But I have to hope we're better then this. Disgusting. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rustompmody at gmail.com Tue Feb 1 01:14:45 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 31 Jan 2011 22:14:45 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: On Feb 1, 1:35 am, Raymond Hettinger wrote: > However, even the parts of the standard library written in pure Python > don't seem to be getting read anymore, so I'm still inclined to > attribute the issue to 1) inconvenient placement of source code, > 2) a largish code base, and 3) possibly a cultural shift. There is another thread running where this was said (by a python developer?) > Actually I don't even understand how can IDLE source code quality have > anything to do with python success or future adoption, as you implied > in your statements. > High priority bugs get fixed first. IDLE source code is clearly not a > high priority issue, hence it doesn't get fixed: end of story. Now if we can put aside for a moment the fact that the person to whom this was said specializes in the art of raising others' blood pressures and making them say what they may not otherwise have said, it should be clear that this priority is at cross purposes with Raymond's. In short (at the risk of belonging to the equivalence class of others whose names start with R) I would suggest a 4th point: Code cruft Please note: I am thankful to all python devs for giving me python. Its just that when functionality becomes as large as it is for python and the target is fast moving, keeping code spic and span will generally be perceived to be a priority that has crossed the point of diminishing returns. Consequence: noobs have a higher barrier to entry than earlier From rustompmody at gmail.com Tue Feb 1 01:16:26 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 31 Jan 2011 22:16:26 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: <8c8e0704-d262-41e7-9791-d629ac287012@y36g2000pra.googlegroups.com> On Feb 1, 11:14?am, rusi wrote: > On Feb 1, 1:35 am, Raymond Hettinger wrote: snipped O O wrong thread... sorry! From rustompmody at gmail.com Tue Feb 1 01:25:48 2011 From: rustompmody at gmail.com (rusi) Date: Mon, 31 Jan 2011 22:25:48 -0800 (PST) Subject: Use the Source Luke References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> <4d473a2c$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: The following, meant for this thread, went to another my mistake :-) -------------------------- On Feb 1, 1:35 am, Raymond Hettinger wrote: > However, even the parts of the standard library written in pure Python > don't seem to be getting read anymore, so I'm still inclined to > attribute the issue to 1) inconvenient placement of source code, > 2) a largish code base, and 3) possibly a cultural shift. There is another thread running where this was said (by a python developer?) > Actually I don't even understand how can IDLE source code quality have > anything to do with python success or future adoption, as you implied > in your statements. > High priority bugs get fixed first. IDLE source code is clearly not a > high priority issue, hence it doesn't get fixed: end of story. Now if we can put aside for a moment the fact that the person to whom this was said specializes in the art of raising others' blood pressures and making them say what they may not otherwise have said, it should be clear that this priority is at cross purposes with Raymond's. In short (at the risk of belonging to the equivalence class of others whose names start with R) I would suggest a 4th point: Code cruft Please note: I am thankful to all python devs for giving me python. Its just that when functionality becomes as large as it is for python and the target is fast moving, keeping code spic and span will generally be perceived to be a priority that has crossed the point of diminishing returns. Consequence: noobs will have a higher barrier to entry than earlier From rantingrick at gmail.com Tue Feb 1 01:38:18 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 31 Jan 2011 22:38:18 -0800 (PST) Subject: Use the Source Luke References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> <4d473a2c$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 1, 12:25?am, rusi wrote: > In short (at the risk of belonging to the equivalence class of others > whose names start with R) I would suggest a 4th point: Code cruft Oh rusi, just come out of the closet already we accept you! :-) From me+list/python at ixokai.io Tue Feb 1 01:47:12 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Mon, 31 Jan 2011 22:47:12 -0800 Subject: Use the Source Luke In-Reply-To: References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> <4d473a2c$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D47AC70.7060705@ixokai.io> On 1/31/11 10:38 PM, rantingrick wrote: > On Feb 1, 12:25 am, rusi wrote: >> In short (at the risk of belonging to the equivalence class of others >> whose names start with R) I would suggest a 4th point: Code cruft > Oh rusi, just come out of the closet already we accept you! :-) First tonight, you find sexism funny; now you find bigotry funny. Disgusting. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From mail at johnohagan.com Tue Feb 1 03:30:19 2011 From: mail at johnohagan.com (John O'Hagan) Date: Tue, 1 Feb 2011 08:30:19 +0000 Subject: Reassign or discard Popen().stdout from a server process Message-ID: <201102010830.20110.mail@johnohagan.com> I'm starting a server process as a subprocess. Startup is slow and unpredictable (around 3-10 sec), so I'm reading from its stdout until I get a line that tells me it's ready before proceeding, in simplified form: import subprocess proc = subprocess.Popen(['server', 'args'], stdout=subprocess.PIPE) while proc.stdout.readline() != "Ready.\n": pass Now I can start communicating with the server, but I eventually realised that as I'm no longer reading stdout, the pipe buffer will fill up with output from the server and before long it blocks and the server stops working. I can't keep reading because that will block - there won't be any more output until I send some input, and I don't want it in any case. To try to fix this I added: proc.stdout = os.path.devnull which has the effect of stopping the server from failing, but I'm not convinced it's doing what I think it is. If I replace devnull in the above line with a real file, it stays empty although I know there is more output, which makes me think it hasn't really worked. Simply closing stdout also seems to stop the crashes, but doesn't that mean it's still being written to, but the writes are just silently failing? In either case I'm wary of more elusive bugs arising from misdirected stdout. Is it possible to re-assign the stdout of a subprocess after it has started? Or just close it? What's the right way to read stdout up to a given line, then discard the rest? Thanks, john From clp2 at rebertia.com Tue Feb 1 04:31:28 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 1 Feb 2011 01:31:28 -0800 Subject: Reassign or discard Popen().stdout from a server process In-Reply-To: <201102010830.20110.mail@johnohagan.com> References: <201102010830.20110.mail@johnohagan.com> Message-ID: On Tue, Feb 1, 2011 at 12:30 AM, John O'Hagan wrote: > I'm starting a server process as a subprocess. Startup is slow and > unpredictable (around 3-10 sec), so I'm reading from its stdout until I get a > line that tells me it's ready before proceeding, in simplified form: > > import subprocess > proc = subprocess.Popen(['server', 'args'], stdout=subprocess.PIPE) > while proc.stdout.readline() != "Ready.\n": > ? ?pass > > Now I can start communicating with the server, but I eventually realised that > as I'm no longer reading stdout, the pipe buffer will fill up with output from > the server and before long it blocks and the server stops working. > > I can't keep reading because that will block - there won't be any more output > until I send some input, and I don't want it in any case. > > To try to fix this I added: > > proc.stdout = os.path.devnull > > which has the effect of stopping the server from failing, but I'm not convinced > it's doing what I think it is. If I replace devnull in the above line with a > real file, it stays empty although I know there is more output, which makes me > think it hasn't really worked. Indeed. proc.stdout is a file, whereas os.devnull is merely a path string; the assignment is nonsensical type-wise. > Simply closing stdout also seems to stop the crashes, but doesn't that mean > it's still being written to, but the writes are just silently failing? In Based on some quick experimentation, yes, more or less. > either case I'm wary of more elusive bugs arising from misdirected stdout. > > Is it possible to re-assign the stdout of a subprocess after it has started? I think that's impossible. (Most of Popen's attributes probably should be read-only properties to clarify that such actions are don't have the intended effect.) > What's the right way to read stdout up to a given line, then > discard the rest? I would think calling Popen.communicate() after you've reached the given line should do the trick. http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate Just ignore its return value. However, that does require sending the input all at once in a single chunk, which it sounds like may not be feasible in your case; if so, I have no idea how to do it cleanly. Cheers, Chris -- http://blog.rebertia.com From flebber.crue at gmail.com Tue Feb 1 05:20:24 2011 From: flebber.crue at gmail.com (flebber) Date: Tue, 1 Feb 2011 02:20:24 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: On Feb 1, 4:39?am, rantingrick wrote: > IDLE: A cornicopia of mediocrity and obfuscation. > -- by Rick Johnson > > IDLE --which is the Python Integrated Development and Learning > Environment-- was once the apple of Guido's eye but has since > degenerated into madness many years ago and remains now as the shining > jewel "show piece" on the proverbial python wall of shame. A once > mighty dream of "programming for everyone" that is now nothing more > than an example of "how NOT to program". > > IDLE contains some of the worst code this community has created. Bad > design patterns, tacked on functionality, blasphemous styling, and > piss poor packaging. There seems to be no guiding goals or game-plan. > And year after year if IDLE *does* get any attention it's just more > haphazard code thrown into the mix by someone who has gone blind from > reading the source. However we cannot blame the current maintainer (if > any such even exists!) because NOBODY can maintains such a spaghetti > mess that this package has become! > > If we would have had a proper game plan from day one i believe we > could have avoided this catastrophe. Follows is an outline of the > wrongs with some suggestions to right them... > > ?* First of all the main two modules "PyShell" and "EditorWindow" are > laid out in such a non sequential way that it is virtually impossible > to follow along. We should have had a proper app instance from which > all widgets where combined. The main app should have followed a > "common sense" sequential mentality of... > > ?* subclassing the tk.Toplevel > ?* initializing instance variables > ?* creating the main menu > ?* creating the sub widgets > ?* declaring internal methods > ?* declaring event handlers > ?* then interface/generic methods. > > ?This is the recipe for order AND NOT CHAOS! What we have now is utter > chaos! When we have order we can read source code in a sequential > fashion. When we have order we can comprehend what we read. And when > we have order we can maintain a library/package with ease. However > sadly we DO NOT have order, we have CHAOS, CHAOS, and more CHAOS! > > * The underlying sub widgets should have started with their own proper > order of "declared" initialization. And all events should be handled > in the widget at hand NOT outsourced to some other class! > > ?* One of the biggest design flaws is the fact that outside modules > manipulate the main editor/pyshells events. This is a terrible way to > code. For example the AutoCompleteWindow takes over the tab event.... > > ? #-- Puesdo Code --# > ? # in editor window __init__ > ? self.autocomplete = AutoComplete(blah) > ? # in editor window onKeyPress(blah) > ? if key == 'Tab' and blah: > ? ? ? self.autocomplete.show_tip(blah) > ? elif key == 'Escape' and acw.is_visibe(): > ? ? ? self.autocomplete.hide() > > ?This is a bad design! The main editor window should handle all its > own events AND THEN call outside class methods when needed. We don't > want "Mommy" classes telling the kids what to do, when to eat, when to > sleep, and when to excrete! We should create our objects with the > virtue of self reliance and responsibility!. The Colorizer, > ParenMatch, textView, TreeWidget, CallTips, and many other modules are > guilty of "event stealing" also. Event functionality must be handled > in the widget itself, NOT stolen and handled in an outside class. When > we split up sequential code we get CHAOS! > > ?* Another bad choice was creating custom reusable widgets > (Tabbedpages, FindDialog, ReplaceDialog, etc...) and leaving them in > idlelib. These should have been moved into the lib-tk module where > they would be more visible to python programmers AND we could reduce > the cruft in the idlelib! Remember, when we create more files, > folders, and objects we create CHAOS. And nobody can learn from CHAOS! > > ?* Another blasphemy is the fact that every module should include some > sort of test to display its usage. If the module is a GUI widget then > you MUST show how to use the widget in a window. Sadly like all > everything else, idlelib is devoid of examples and testing. And the > very few tests that DO exists just blow chunks! > > ?* Last but not least idlelib does not follow PEP8 or ANY convention. > So much so that it seems the developers snubbed their nose at such > conventions! We are missing doc strings and comments. We have built- > ins being re-bound! Just code horror after code horror. > > These are just the top of the list. The peak of a huge iceberg that > threatens to sink the community in the arms of chaos never to return. > I am beginning to believe that this community is either made of > amateurs due to this lackluster code in the stdlib. However it could > be that the folks are really professional and refuse to work on such a > horrible code base (which i understand). I am going with the latter. > > When are we going to demand that these abominations be rectified? How > much longer must we wait? A year? Ten years?... i don't think Python > will survive another ten years with this attitude of obfuscation, and > mentality of mediocrity. > > -- rr: disappointed and annoyed! Sorry Rick too boring....trying to get bored people to bite at your ultra lame post yawn........... From jeanmichel at sequans.com Tue Feb 1 05:27:16 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 01 Feb 2011 11:27:16 +0100 Subject: multiple values for keyword argument In-Reply-To: <929BEBF809CC4B2AA4D08104B266423D@mycomputer> References: <9f669337-6116-4442-9c7e-54b0051e33a2@8g2000prb.googlegroups.com> <8qijsgFgu1U1@mid.dfncis.de> <4D443631.3000502@stoneleaf.us> <6f1dd6fbbc04d2788b2b191e3e407887.squirrel@cruziomail.cruzio.com> <4D470F18.9000103@sequans.com> <929BEBF809CC4B2AA4D08104B266423D@mycomputer> Message-ID: <4D47E004.5080900@sequans.com> Patty wrote: > >> patty at cruzio.com wrote: >>> I have been avoiding understanding this 'self', >>> [snip] >>> Regards, >>> >>> Patty >>> >> What is to be understood ?? self references the instance. Did I miss >> something ? >> >> JM >> >> >> > > Yes, there was more. And it's been fully explained at this point. > > Patty Hmm... I re-read the thread just in case ... Anyway. I'd like to read suggestions for self replacements... Currently 'yo' have been proposed. I'm just curious, I promise I won't make any comment :D JM From darksideandroid at gmail.com Tue Feb 1 05:43:19 2011 From: darksideandroid at gmail.com (Darkside Android) Date: Tue, 1 Feb 2011 02:43:19 -0800 (PST) Subject: Installing Suds for Python 2.6.1 on Mac OS X Message-ID: I'd like to test my SOAP-based web service from Textmate (PyMate) however I'm running into some trouble trying to get suds configured on my Mac. I was able to install it from Terminal however I'm getting the message each time I run the script: ImportError: No module named suds What do you recommend I do? I think it might have something to do with the PYTHONPATH but I have no idea where this is? From antonyjeevaraj at gmail.com Tue Feb 1 06:51:47 2011 From: antonyjeevaraj at gmail.com (antony jeevaraj) Date: Tue, 1 Feb 2011 03:51:47 -0800 (PST) Subject: EARN $350+/DAY MOST ADVANCED MONEY MAKING SYSTEM Message-ID: <23226c63-b98d-4dc8-bf7f-78d795aaf81a@o39g2000prb.googlegroups.com> EARN $350+/DAY MOST ADVANCED MONEY MAKING SYSTEM International company expanding 23 people needed immediately! Earn up to $500- $1500 Part Time Per Week Earn up to $3,000- $5,000 + Full Time You will be TRAINED to use the internet, mail and phone from home to build an international business! We are NOT a company based on family and friends, door-to-door sales, or telemarketing. In fact we are not even looking for sales people and there is no need to meet with people! We have been in business 29 years: established in 70 countries we will TRAIN you from your home to be successful. We have complete start to finish training with one-on-one personal mentoring for each new person, along with group telephone training programs to ensure your continued success. Serious people with a STRONG desire can earn up to 6 figures in only one year? Read more: http://filesmy.com/0i8nT From clp2 at rebertia.com Tue Feb 1 07:30:12 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 1 Feb 2011 04:30:12 -0800 Subject: Installing Suds for Python 2.6.1 on Mac OS X In-Reply-To: References: Message-ID: On Tue, Feb 1, 2011 at 2:43 AM, Darkside Android wrote: > I'd like to test my SOAP-based web service from Textmate (PyMate) > however I'm running into some trouble trying to get suds configured on > my Mac. I was able to install it from Terminal however I'm getting the > message each time I run the script: Can you successfully import it when running Python in Terminal? > ImportError: No module named suds > > What do you recommend I do? I think it might have something to do with > the PYTHONPATH but I have no idea where this is? Have you set the TM_PYTHON Shell Variable appropriately in TextMate's Preferences (Advanced section)? Cheers, Chris -- http://blog.rebertia.com From rantingrick at gmail.com Tue Feb 1 07:38:49 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 04:38:49 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: On Feb 1, 4:20?am, flebber wrote: > Sorry Rick too boring....trying to get bored people to bite at your > ultra lame post yawn........... Well reality and truth both has a tendency to be boring. Why? Well because we bathe in them daily. We have come accustomed, acclimated, and sadly complacent of the ill state of our stdlib. Yes, boring. However we must be aware of these things. From awilliam at whitemice.org Tue Feb 1 07:53:13 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 01 Feb 2011 07:53:13 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: Message-ID: <1296564793.16858.0.camel@linux-yu4c.site> On Tue, 2011-02-01 at 04:38 -0800, rantingrick wrote: > On Feb 1, 4:20 am, flebber wrote: > > Sorry Rick too boring....trying to get bored people to bite at your > > ultra lame post yawn........... > Well reality and truth both has a tendency to be boring. Even more true of pointless and drawn-out pontificating. If you despise IDLE so much - use one of the many other IDE's that support Python; move on. From __peter__ at web.de Tue Feb 1 07:59:07 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 Feb 2011 13:59:07 +0100 Subject: argparse: combine current option value with positional argument Message-ID: I'd like to capture the current value of an option --prefix= along with a positional value as it is seen by argparse. Example: python script.py -p1 alpha beta -p2 gamma -p3 should result in a list [(1, "alpha"), (1, "beta"), (2, "gamma")] Here's a working script that uses --name= instead of of just : $ cat tmp.py import argparse parser = argparse.ArgumentParser() parser.add_argument("-p", "--prefix") parser.add_argument("-n", "--name") class Namespace(object): def __init__(self): self.pairs = [] self.prefix = None def set_name(self, value): if value is not None: self.pairs.append((self.prefix, value)) name = property(None, set_name) ns = Namespace() parser.parse_args(namespace=ns) print ns.pairs $ python tmp.py -p1 -nalpha -nbeta -p2 -ngamma [('1', 'alpha'), ('1', 'beta'), ('2', 'gamma')] However, modifying the --name option to a positional with parser.add_argument("name", nargs="*") results in an error: $ python tmp2.py -p1 alpha beta -p2 gamma usage: tmp2.py [-h] [-p PREFIX] [name [name ...]] tmp2.py: error: unrecognized arguments: gamma Am I missing a simple way to avoid that? Peter PS: I've not yet "used the source" ;) From rantingrick at gmail.com Tue Feb 1 08:38:26 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 05:38:26 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> On Feb 1, 6:53?am, Adam Tauno Williams wrote: > If you despise IDLE so much - use one of the many other IDE's that > support Python; ?move on. Not exactly. Can we continue to ignore such lackluster and shabby code in OUR stdlib. Remember the code reflects on all of us! From andre.roberge at gmail.com Tue Feb 1 09:04:16 2011 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9?=) Date: Tue, 1 Feb 2011 06:04:16 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> Message-ID: On Tuesday, February 1, 2011 9:38:26 AM UTC-4, Richard "rantingrick" Johnson wrote: > On Feb 1, 6:53?am, Adam Tauno Williams wrote: > > > If you despise IDLE so much - use one of the many other IDE's that > > support Python; ?move on. > > Not exactly. Can we continue to ignore such lackluster and shabby code > in OUR stdlib. Remember the code reflects on all of us! Could you enlighten us and tell us what code YOU contributed to the stdlib? Andr? From jeanmichel at sequans.com Tue Feb 1 09:27:01 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 01 Feb 2011 15:27:01 +0100 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> Message-ID: <4D481835.4040400@sequans.com> rantingrick wrote: > On Feb 1, 6:53 am, Adam Tauno Williams wrote: > > >> If you despise IDLE so much - use one of the many other IDE's that >> support Python; move on. >> > > Not exactly. Can we continue to ignore such lackluster and shabby code > in OUR stdlib. Remember the code reflects on all of us! > Can we continue to ignore such lackluster and shabby trolls in OUR mailing list ? Fortunately, the behavior of one does not reflect the behavior of us all. In a more serious way, just count the people who second your prosposition. It's around 0. It is usually a good sign that you're wrong. This rule kinda applies to anyone, don't take it personnaly. ... or maybe you're just trolling, in which case you can thank me for feeding. JM From anikom15 at gmail.com Tue Feb 1 09:35:28 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Tue, 01 Feb 2011 06:35:28 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> Message-ID: <1296570928.31440.1.camel@localhost.localdomain> Man you're a real comedian. This is a hilarious thread. Keep up the good work! On Tue, 2011-02-01 at 05:38 -0800, rantingrick wrote: > On Feb 1, 6:53 am, Adam Tauno Williams wrote: > > > If you despise IDLE so much - use one of the many other IDE's that > > support Python; move on. > > Not exactly. Can we continue to ignore such lackluster and shabby code > in OUR stdlib. Remember the code reflects on all of us! -------------- next part -------------- An HTML attachment was scrubbed... URL: From darksideandroid at gmail.com Tue Feb 1 10:05:44 2011 From: darksideandroid at gmail.com (Darkside Android) Date: Tue, 1 Feb 2011 07:05:44 -0800 (PST) Subject: Installing Suds for Python 2.6.1 on Mac OS X References: Message-ID: On Feb 1, 4:30?am, Chris Rebert wrote: > On Tue, Feb 1, 2011 at 2:43 AM, Darkside Android > > wrote: > > I'd like to test my SOAP-based web service from Textmate (PyMate) > > however I'm running into some trouble trying to get suds configured on > > my Mac. I was able to install it from Terminal however I'm getting the > > message each time I run the script: > > Can you successfully import it when running Python in Terminal? > > > ImportError: No module named suds > > > What do you recommend I do? I think it might have something to do with > > the PYTHONPATH but I have no idea where this is? > > Have you set the TM_PYTHON Shell Variable appropriately in TextMate's > Preferences (Advanced section)? > > Cheers, > Chris > --http://blog.rebertia.com Thanks for the feedback Chris. I was able to figure it out this morning. I needed to run 'sudo easy_install -z suds' from Terminal. From rantingrick at gmail.com Tue Feb 1 10:14:41 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 07:14:41 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> Message-ID: <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> On Feb 1, 8:27?am, Jean-Michel Pichavant wrote: > In a more serious way, just count the people who second your > prosposition. It's around 0. It is usually a good sign that you're > wrong. This rule kinda applies to anyone, don't take it personnaly. Well your statment completely ignores the silent majority. Are you telling me that this sloth of trolls, minions, and flamers that have so far replied are represetative of this fine community. Gawd i hope NOT!. Here is a list of the compiled personalities... #-- Embedded Trolls and Minions --# Steven D'Aprano(smart and witty (annoying) troll) Stephan Hansen (controversy troll) Ben Finny (haughty troll) alex23(angry/dangerous troll) Tyler Littlefeild(confused troll) Bryan ? (annoying troll) Corey Richarson Nicholas Devenish Alexander Kapps rusi ? Andre ? Geremy Condra (troll-wagoneer) Ethan Furman Noah Hall Adam Skutt Arndt Rodger Schnieder Mark Roseman (Tkinter's minion) #-- Occasonal Flamers --# Micheal Torrie Grant Edwards MRAB Thomas L Shinnink Peter Otten Giampaolo Rodola Giacomo Boffi malcom ? Zeissmann Mel Owen Jacobson Robert ? #-- Complete Nobodys --# Bill Felton flebber #-- MIA --# GvR Steve Holden #-- Moderates --# Richard Johnson Terry Reedy Kevin Walzer Octavian Rasnita Robert Kern Brenden Simon Tommy Grav Martin V Leowis Ian ? Tim Chase CM Bob Martin Neil Hodgenson Robin Dunn Benjamin Kaplan Jerry Hill Patty ? Martin Gregorie Albert van der Horst Martin P Hellwig jmfauth Steven Howe Antoine Pitrou Hank Fay Katie T Gerry Reno Stefen Behnel 26 moderates 31 trolls, minions, sockpuppets, and or flamers 2 missing in action -------------------- = This community needs serious help! From enalicho at gmail.com Tue Feb 1 10:26:17 2011 From: enalicho at gmail.com (Noah Hall) Date: Tue, 1 Feb 2011 15:26:17 +0000 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> Message-ID: On Tue, Feb 1, 2011 at 3:14 PM, rantingrick wrote: > #-- Embedded Trolls and Minions --# > Steven D'Aprano(smart and witty (annoying) troll) > Stephan Hansen (controversy troll) > Ben Finny (haughty troll) > alex23(angry/dangerous troll) > Tyler Littlefeild(confused troll) > Bryan ? (annoying troll) > Corey Richarson > Nicholas Devenish > Alexander Kapps > rusi ? > Andre ? > Geremy Condra (troll-wagoneer) > Ethan Furman > Noah Hall > Adam Skutt > Arndt Rodger Schnieder > Mark Roseman (Tkinter's minion) These people, including myself, aren't trolls nor minions. They just don't agree with you. And on the topic of IDLE, I agree the coding's not great, but I disagree with it being a problem for the Python community. I've never, ever seen a thread saying "OMG, WHAT DOES THIS IDLE SOURCE CODE EXTRACT MEAN? PLEASE HELP, I CAN'T UNDERSTAND IDLE, THEREFORE I CAN NOT USE Tkinter! I'm leaving Python, Visual Basic's for me from now on! NO DAMN IDLE TO MESS UP EVERYTHING, YOU SEE?" From mail at johnohagan.com Tue Feb 1 10:26:37 2011 From: mail at johnohagan.com (John O'Hagan) Date: Tue, 1 Feb 2011 15:26:37 +0000 Subject: Reassign or discard Popen().stdout from a server process In-Reply-To: References: <201102010830.20110.mail@johnohagan.com> Message-ID: <201102011526.39023.mail@johnohagan.com> On Tue, 1 Feb 2011, Chris Rebert wrote: > On Tue, Feb 1, 2011 at 12:30 AM, John O'Hagan wrote: > > I'm starting a server process as a subprocess. Startup is slow and > > unpredictable (around 3-10 sec), so I'm reading from its stdout until I > > get a line that tells me it's ready before proceeding, in simplified > > form: > > > > import subprocess > > proc = subprocess.Popen(['server', 'args'], stdout=subprocess.PIPE) > > while proc.stdout.readline() != "Ready.\n": > > pass > > > > Now I can start communicating with the server, but I eventually realised > > that as I'm no longer reading stdout, the pipe buffer will fill up with > > output from the server and before long it blocks and the server stops > > working. > > > > I can't keep reading because that will block - there won't be any more > > output until I send some input, and I don't want it in any case. > > > > To try to fix this I added: > > > > proc.stdout = os.path.devnull > > > > which has the effect of stopping the server from failing, but I'm not > > convinced it's doing what I think it is. If I replace devnull in the > > above line with a real file, it stays empty although I know there is > > more output, which makes me think it hasn't really worked. > > Indeed. proc.stdout is a file, whereas os.devnull is merely a path > string; the assignment is nonsensical type-wise. My mistake, of course I meant open(os.path.devnull). > > Simply closing stdout also seems to stop the crashes, but doesn't that > > mean it's still being written to, but the writes are just silently > > failing? In > > Based on some quick experimentation, yes, more or less. > > > either case I'm wary of more elusive bugs arising from misdirected > > stdout. > > > > Is it possible to re-assign the stdout of a subprocess after it has > > started? > > I think that's impossible. (Most of Popen's attributes probably should > be read-only properties to clarify that such actions are don't have > the intended effect.) I don't doubt what you say, but attempting to assign it does seem to do something, as it consistently stops the crashes which occur otherwise. What it does, I have no idea. > > What's the right way to read stdout up to a given line, then > > discard the rest? > > I would think calling Popen.communicate() after you've reached the > given line should do the trick. > http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate > Just ignore its return value. However, that does require sending the > input all at once in a single chunk, which it sounds like may not be > feasible in your case; if so, I have no idea how to do it cleanly. Yes, unfortunately I need to send a lot of precisely-timed short strings, and communicate() blocks after the first call. I tried calling stdout.readline() the right number of times after each input, but that seems fiddly and fragile - for example the number of lines of output is not guaranteed and may vary in the case of errors, and also the extra reads had a noticeable effect on latency, which is important in this case. So far my best bet seems to be closing stdin, which doesn't seem very clean, but it does what I want and seems to be just as fast as using stdin=open(os.devnull) in the Popen call in the first place. Thanks, John From gerald.britton at gmail.com Tue Feb 1 10:28:02 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 1 Feb 2011 10:28:02 -0500 Subject: How can I tell if I am inside a context manager? Message-ID: I'd like to know how (perhaps with the inspect module) I can tell if I am running in a context manager. e.g. class f(): def __init__(s): pass def __enter__(s): return s def __exit__(s,a,b,c): return None def g(): x = f() # insert code here to return False, since I am not in a context manager on f: with h as f(): # insert code here to return True, since I am in a context manager on f: -- Gerald Britton From subhabangalore at gmail.com Tue Feb 1 10:36:38 2011 From: subhabangalore at gmail.com (Subhabrata) Date: Tue, 1 Feb 2011 07:36:38 -0800 (PST) Subject: Looking for Remote Python Project References: <4d1ff594-925b-457e-be62-7e4ca32ae136@33g2000pru.googlegroups.com> Message-ID: <28ea3842-2f26-4cb4-8aaa-4fdfd2d8c36f@o7g2000prn.googlegroups.com> On Feb 1, 8:45?am, Alan Meyer wrote: > On 01/29/2011 04:19 PM,joy99wrote: > > > Dear Room, > > > I am a Python Programmer from India(New Delhi Region), and I worked > > for quite a long time in Bangalore. I have been working in Python for > > the last 4 years or so. I have successfully built around 15 projects > > in Python. I am looking for some remote Python Projects, which can be > > done from home. > > > If any one knows of anything, I may be helpful enough. > > > Best Regards, > > Subhabrata. > > Subharata, > > Would you be willing to tell us what a programmer with your level of > experience typically charges per hour for his services? > > I'm not in a position to hire anyone, I'm just a programmer myself. ?But > I'm curious about rates in India vs. the U.S., where I live and work. > > Thanks and good luck with your efforts to get work. > > ? ? ?Alan Alan, Usually if any one pays USD 1 per hr in India it is good, USD 2 per hour is handsome, very rare people pay USD 3 to 4 per hour, but I know some people in India charge USD 20/25 per line I do not know their hourly rate but as I know they just run some consultancy and do not do any job. The people who give in range of USD 1-4/hr also gives some perks like performance related bonus, housing, medical, etc. But again rate varies. Delhi/Gurgaon gives highest pay, followed by Bangalore/Hyderabad, then comes Chennai, Mumbai gives moderate, Kolkata/Mysore/Bhubaneswar are casual players, they neither have serious places of work nor any good environment. In India, lots of development goes on in the government sector but right now they are paying very high, generally they pay 20-30% lower than private sector, but job security is there. Hope this information helps. Best Regards, Subhabrata. From tjreedy at udel.edu Tue Feb 1 10:54:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 Feb 2011 10:54:26 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: On 2/1/2011 12:13 AM, rantingrick wrote: > On Jan 31, 4:17 pm, Kevin Walzer wrote: >> Rick, > Yes. IDLE is first and foremost a tool to get work done. However we > should not ignore the fact that IDLE could also be a great learning > resource for Tkinter GUI's and other subjects. Why not clean up the > code base? We could start small. First, move the custom widgets like > textView, Tabbedpages, FindDialog, ReplaceDialog, and TreeWidget into > the lib-tk for others to use more freely. Then we can modify the > "event robbers" CallTips, ParenMatch, and ColorDelegator. Perhaps, after the repository moves from svn to hg, some 'we' will. Maybe by then, you will have had your fun and be ready to work. Maybe Kevin would help a bit. Such a project would be carried out on the tracker and idle-sig mailing list. Normal decorum would be required -- no ranting or insulting. The first thing to do, in my opinion, is to review existing patches on the tracker. > Well some changes and improvements can be made to the UI as well. There is patch on the tracker, by G. Polo, as I remember, to replace tk widgets with the newer themed ttk widgets. It needs to be reviewed and tested. To make a big change (or proceed with any refactoring) better automated testing would be very useful. -- Terry Jan Reedy From rantingrick at gmail.com Tue Feb 1 11:00:26 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 08:00:26 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> Message-ID: <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> On Feb 1, 9:26?am, Noah Hall wrote: > On Tue, Feb 1, 2011 at 3:14 PM, rantingrick wrote: > > #-- Embedded Trolls and Minions --# > > Steven D'Aprano(smart and witty (annoying) troll) > > Stephan Hansen (controversy troll) > > Ben Finny (haughty troll) > > alex23(angry/dangerous troll) > > Tyler Littlefeild(confused troll) > > Bryan ? (annoying troll) > > Corey Richarson > > Nicholas Devenish > > Alexander Kapps > > rusi ? > > Andre ? > > Geremy Condra (troll-wagoneer) > > Ethan Furman > > Noah Hall > > Adam Skutt > > Arndt Rodger Schnieder > > Mark Roseman (Tkinter's minion) > > These people, including myself, aren't trolls nor minions. They just > don't agree with you. No they are trolls and they have demonstrated trollish behavior on many occasions. Some have even threatened to kill me. Can you believe that? If you will look over my moderate list you will see that many do not agree with me completely however they express their disagreement in a moderate way. On the other hand the trolls and flamers just hurl insults and inflammatory speech. The trolls and flamers don't offer any argument to back up their statements. They only hurl more emotional bile. > And on the topic of IDLE, I agree the coding's not great, See now you are offering truth in your argument! Keep this up and i'll move you over to the occasional flamers group. Then over time, if you can demonstrate an ability to engage in lively discussion based on facts and not emotion, i *may* even move you into the moderates group. I believe in every troll there is a rational person just waiting to break free. > but I > disagree with it being a problem for the Python community. I've never, > ever seen a thread saying "OMG, WHAT DOES THIS IDLE SOURCE CODE > EXTRACT MEAN? PLEASE HELP, Thats because even the maintainers of IDLE don't understand completely how it works. It is a true nightmare of code horror -- of *epic* proportions! > I CAN'T UNDERSTAND IDLE, THEREFORE I CAN > NOT USE Tkinter! I'm leaving Python, Visual Basic's for me from now > on! NO DAMN IDLE TO MESS UP EVERYTHING, YOU SEE?" Well this would be expected of an emotionally driven creature. One who cannot wield the tools of reason and logic. I pity these poor souls just as i pity the trolls in the troll group. But like they say: When your at the bottom there is only one direction to go... Strait up! Sadly some of these folks may be suffering from gimbal lock with their up vector pointing strait down. From wolfgang at rohdewald.de Tue Feb 1 11:04:44 2011 From: wolfgang at rohdewald.de (Wolfgang Rohdewald) Date: Tue, 1 Feb 2011 17:04:44 +0100 Subject: How can I tell if I am inside a context manager? In-Reply-To: References: Message-ID: <201102011704.44934.wolfgang@rohdewald.de> On Dienstag 01 Februar 2011, Gerald Britton wrote: > I'd like to know how (perhaps with the inspect module) I can > tell if I am running in a context manager. class f(object): def __init__(self): self.inContext = False def __enter__(self): self.inContext = True return self def __exit__(self,a,b,c): self.inContext = False return None x = f() print 'not within:', x.inContext with f() as h: print 'within:', h.inContext -- Wolfgang -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Tue Feb 1 11:06:54 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 01 Feb 2011 11:06:54 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: <9f671$4d482f9d$4275d90a$23214@FUSE.NET> On 2/1/11 10:54 AM, Terry Reedy wrote: > Maybe Kevin would help a bit. Probably not--IDLE is good enough for my needs. I've submitted some (rather extensive) patches for things that annoyed me and got in my way, and they eventually made it in. (The classic open source pathway--scratching my own itch.) Beyond that, though, hacking on IDLE isn't a project I have time for. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rantingrick at gmail.com Tue Feb 1 11:18:07 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 08:18:07 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: <4b4eeb69-133b-4aac-8817-6d74ebdae0ac@m7g2000vbq.googlegroups.com> On Feb 1, 9:54?am, Terry Reedy wrote: > On 2/1/2011 12:13 AM, rantingrick wrote: > > > On Jan 31, 4:17 pm, Kevin Walzer ?wrote: > >> Rick, > > Yes. IDLE is first and foremost a tool to get work done. However we > > should not ignore the fact that IDLE could also be a great learning > > resource for Tkinter GUI's and other subjects. Why not clean up the > > code base? We could start small. First, move the custom widgets like > > textView, Tabbedpages, FindDialog, ReplaceDialog, and TreeWidget into > > the lib-tk for others to use more freely. Then we can modify the > > "event robbers" CallTips, ParenMatch, and ColorDelegator. > > Perhaps, after the repository moves from svn to hg, some 'we' will. Well the best attribute of IDLE is backward compatibility -- there is none to worry about. IDLE is not a module with an interface, it's just a tool. So we could change anything we want without worry of causing code breakage. There is not good reason NOT to fix IDLE. > Maybe Kevin would help a bit. I was hoping he would get involved however his last post proved otherwise. I know he has his own projects however he would have been a valuable asset for the ttk theming stuff. > Such a project would be carried out on the tracker and idle-sig mailing > list. Normal decorum would be required -- no ranting or insulting. The > first thing to do, in my opinion, is to review existing patches on the > tracker. Agreed. Terry (or anyone) can you give some link to info on "hg" so i can study up on this topic? Thanks > > Well some changes and improvements can be made to the UI as well. > > There is patch on the tracker, by G. Polo, as I remember, to replace tk > widgets with the newer themed ttk widgets. It needs to be reviewed and > tested. To make a big change (or proceed with any refactoring) better > automated testing would be very useful. Yes "turning on" the themes would be a huge improvement. I also wished IDLE would look better. From rantingrick at gmail.com Tue Feb 1 11:23:55 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 08:23:55 -0800 (PST) Subject: argparse: combine current option value with positional argument References: Message-ID: On Feb 1, 6:59?am, Peter Otten <__pete... at web.de> wrote: > I'd like to capture the current value of an option --prefix= along > with a positional value as it is seen by argparse. Have you seen the handy optphart module yet? I believe its in alpha2 currently but very stable. http://tinyurl.com/optphart From tyler at tysdomain.com Tue Feb 1 11:29:22 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 01 Feb 2011 09:29:22 -0700 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> Message-ID: <4D4834E2.2060408@tysdomain.com> >See now you are offering truth in your argument! Keep this up and i'll >move you over to the occasional flamers group. Then over time, if you >can demonstrate an ability to engage in lively discussion based on >facts and not emotion, i *may* even move you into the moderates group. O no, whatever shall I do. I apparently have no hope of being moved into the moderates group because I don't agree with him. I hope everyone will excuse me now, I must dash off to slit my wrists in a tub of warm water and listen to Free Bird, while morning over the fact that I may *never* get moved into RR's moderate's group. Tisk tisk. From gerald.britton at gmail.com Tue Feb 1 11:34:11 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 1 Feb 2011 11:34:11 -0500 Subject: How can I tell if I am inside a context manager? Message-ID: On Dienstag 01 Februar 2011, Gerald Britton wrote: > I'd like to know how (perhaps with the inspect module) I can > tell if I am running in a context manager. >>class f(object): >> def __init__(self): >> self.inContext = False >> def __enter__(self): >> self.inContext = True >> return self >> def __exit__(self,a,b,c): >> self.inContext = False >> return None >> x = f() >> print 'not within:', x.inContext >> with f() as h: >> print 'within:', h.inContext yes, of course, but in this case I may not modify the class. try it with open: x = open('somefile') # return false since not in a context with open('somefile') as x # return true since in a context. -- Wolfgang -- Gerald Britton From rantingrick at gmail.com Tue Feb 1 12:26:00 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 09:26:00 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> Message-ID: <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> On Feb 1, 10:29?am, "Littlefield, Tyler" wrote: > I hope everyone will > excuse me now, I must dash off to slit ?my wrists in a tub of warm water > and listen to Free Bird, Free Bird! hmm, I would have chosen Chopin's nocturne 48-1 or 72-1 if i was feeling rather melancholy at the moment. Then there is always the funeral march if you really want to lay it on thick. However the march does have a rather lengthy "hopeful" section that may make you give second thoughts. Or perhaps the Berceuse in D-flat Major as a final glorious celebration of life as one journeys beyond the edge of transcendence. If there is a heaven it must sound like this... http://il.youtube.com/watch?v=8TQ-AXJZqtg ...only a man who suffered so greatly can know what true beauty is. RIP Chopin. If you're going to met your end it should be at least to a piece that is truly timeless -- not some reefer+jack induced rockabilly ballad! From redjohn367 at gmail.com Tue Feb 1 12:52:14 2011 From: redjohn367 at gmail.com (Red John) Date: Tue, 1 Feb 2011 09:52:14 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On Feb 1, 10:26?am, rantingrick wrote: > On Feb 1, 10:29?am, "Littlefield, Tyler" wrote: > > > I hope everyone will > > excuse me now, I must dash off to slit ?my wrists in a tub of warm water > > and listen to Free Bird, > > Free Bird! hmm, I would have chosen Chopin's nocturne 48-1 or 72-1 if > i was feeling rather melancholy at the moment. Then there is always > the funeral march if you really want to lay it on thick. However the > march does have a rather lengthy "hopeful" section that may make you > give second thoughts. Or perhaps the Berceuse in D-flat Major as a > final glorious celebration of life as one journeys beyond the edge of > transcendence. If there is a heaven it must sound like this... > > ? ?http://il.youtube.com/watch?v=8TQ-AXJZqtg > > ...only a man who suffered so greatly can know what true beauty is. > RIP Chopin. > > If you're going to met your end it should be at least to a piece that > is truly timeless -- not some reefer+jack induced rockabilly ballad! Go away. You are easily one of the worst (and definitely most annoying) person I've encountered in person or online, which is saying something because I used to frequent 4chan. From malaclypse2 at gmail.com Tue Feb 1 13:15:46 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 1 Feb 2011 13:15:46 -0500 Subject: How can I tell if I am inside a context manager? In-Reply-To: References: Message-ID: On Tue, Feb 1, 2011 at 11:34 AM, Gerald Britton wrote: > x = open('somefile') > # return false since not in a context > with open('somefile') as x > # return true since in a context. > Perhaps something like this: x = open('somefile') if hasattr(x, '__enter__'): return false with open('somefile') as x: do_something() -- Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From sigzero at gmail.com Tue Feb 1 13:21:05 2011 From: sigzero at gmail.com (Robert) Date: Tue, 1 Feb 2011 13:21:05 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: On 2011-02-01 00:13:06 -0500, rantingrick said: > On Jan 31, 4:17?pm, Kevin Walzer wrote: > > Yes. IDLE is first and foremost a tool to get work done. However we > should not ignore the fact that IDLE could also be a great learning > resource for Tkinter GUI's and other subjects. Why not clean up the > code base? We could start small. First, move the custom widgets like > textView, Tabbedpages, FindDialog, ReplaceDialog, and TreeWidget into > the lib-tk for others to use more freely. Then we can modify the > "event robbers" CallTips, ParenMatch, and ColorDelegator. Just small > steps Kevin. It all starts with babysteps. At least we would be doing > something. Currently we are sitting around waiting for a miracle to > happen, and problems are solved by methods, not miracles! > > Well some changes and improvements can be made to the UI as well. Fork it and do it! -- Robert From rantingrick at gmail.com Tue Feb 1 13:23:32 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 10:23:32 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On Feb 1, 11:52?am, Red John wrote: > Go away. You are easily one of the worst (and definitely most > annoying) person I've encountered in person or online, which is saying > something because I used to frequent 4chan. Hmm, that coming from someone who has two posts in this group. And the last he posted was a year ago! Alright, let me add you to the proper category... py> troll_group.append("Red John") From gerald.britton at gmail.com Tue Feb 1 13:38:34 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 1 Feb 2011 13:38:34 -0500 Subject: How can I tell if I am inside a context manager? In-Reply-To: References: Message-ID: "Perhaps something like this:" >>x = open('somefile') >>if hasattr(x, '__enter__'): >> return false >>with open('somefile') as x: >> do_something() >>> class f(): def __init__(s): pass def __enter__(s): return s def __exit__(s,a,b,c): return None >>> x = f() >>> hasattr(x, '__enter__') True >>> with f() as x: hasattr(x,'__enter__') True >>> As you can see, the object has a '__enter__' method regardless of how it was created. Whatever the test, it needs to return False in the first case and True in the second case, without modifying the class definition. Gerald Britton From cousinstanley at gmail.com Tue Feb 1 14:03:28 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 1 Feb 2011 19:03:28 +0000 (UTC) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> <4b4eeb69-133b-4aac-8817-6d74ebdae0ac@m7g2000vbq.googlegroups.com> Message-ID: rantingrick wrote: > Terry (or anyone) can you give some link to info on "hg" > so i can study up on this topic ? http://mercurial.selenic.com/ -- Stanley C. Kitching Human Being Phoenix, Arizona From smokefloat at gmail.com Tue Feb 1 14:07:22 2011 From: smokefloat at gmail.com (David Hutto) Date: Tue, 1 Feb 2011 11:07:22 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: In the grand scope of things...you're all boring. From patty at cruzio.com Tue Feb 1 14:08:54 2011 From: patty at cruzio.com (Patty) Date: Tue, 1 Feb 2011 11:08:54 -0800 Subject: multiple values for keyword argument References: <9f669337-6116-4442-9c7e-54b0051e33a2@8g2000prb.googlegroups.com> <8qijsgFgu1U1@mid.dfncis.de> <4D443631.3000502@stoneleaf.us> <6f1dd6fbbc04d2788b2b191e3e407887.squirrel@cruziomail.cruzio.com> <4D470F18.9000103@sequans.com> <929BEBF809CC4B2AA4D08104B266423D@mycomputer> <4D47E004.5080900@sequans.com> Message-ID: <06448D7A2F5248C4B67E6D4E04D5B4B7@mycomputer> ----- Original Message ----- From: "Jean-Michel Pichavant" To: "Patty" Cc: Sent: Tuesday, February 01, 2011 2:27 AM Subject: Re: multiple values for keyword argument > Patty wrote: >> >>> patty at cruzio.com wrote: >>>> I have been avoiding understanding this 'self', >>>> [snip] >>>> Regards, >>>> >>>> Patty >>>> >>> What is to be understood ?? self references the instance. Did I miss >>> something ? >>> >>> JM >>> >>> >>> >> >> Yes, there was more. And it's been fully explained at this point. >> >> Patty > > > Hmm... I re-read the thread just in case ... Anyway. > I'd like to read suggestions for self replacements... > Currently 'yo' have been proposed. > > I'm just curious, I promise I won't make any comment :D > > JM > > Hi Jean-Michel - I'm sorry. I was getting sensitive about being criticized (or trying to re-explain what I learned and getting it terribly mangled). As it turns out - Westley Martinez pointed out the link about the usage of 'self' : http://en.wikipedia.org/wiki/Self_(computer_science) and these specific two lines showed me why I had been thinking I (we) could replace the word 'self' with any descriptive word (variable) I want. I was thinking of 'self' as a variable and not "In Python, there is no keyword for this, but it exists as the name of the obligatory first argument of all member functions. Conventionally, the name self is used." And since I come from a C background, I thought I could do the following (which the wiki page mentions) :} ) , thus I wanted to use an invented variable name that makes sense to me and helped me as programmer remember where I was in my program when I went and tried to reassign new values, basically override my object at will. But this is what I did not realize: >> "the assignment does not modify the original object, only changing which >> object that the rest of the code in the method refers to" << "Some languages, such as Objective-C, allow assignment to self, although it is deprecated." And then after the thread ended - I read this in the wiki page which totally explains everything -- "Early versions of C++ would let the this pointer be changed; by doing so a programmer could change which object a method was working on" and I learned C++ from an early version so this is Precisely what I thought I could do -- I was envisioning having my object (member function) and then as my program forked different paths, well I thought I could do this very program design. Hopefully that makes more sense as to why I would change the 'name of the obligatory first argument of all member functions'. As other people pointed out, you _can_ make up your own name, 'yo' or anything else, it is by _convention_ to use 'self' and by doing your own thing, could develop a bad habit. Regards, Patty From tjreedy at udel.edu Tue Feb 1 14:15:27 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 Feb 2011 14:15:27 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <4b4eeb69-133b-4aac-8817-6d74ebdae0ac@m7g2000vbq.googlegroups.com> References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> <4b4eeb69-133b-4aac-8817-6d74ebdae0ac@m7g2000vbq.googlegroups.com> Message-ID: On 2/1/2011 11:18 AM, rantingrick wrote: > Well the best attribute of IDLE is backward compatibility -- there is > none to worry about. IDLE is not a module with an interface, it's just > a tool. So we could change anything we want without worry of causing > code breakage. There is not good reason NOT to fix IDLE. That is similar to my view. Of course, there will be an tracker issue and list discussion for any major change. I have even thought it should perhaps be moved to the Tools/ directory, but installation of that is optional. Google codesearch can be used to see what, if anything, anyone imports from idlelib. > Agreed. Terry (or anyone) can you give some link to info on "hg" so i > can study up on this topic? Thanks Joel Spolsky's tutorial is highly regarded as an easier intro than the reference manual. I am about to reread it myself. http://hginit.com/ -- Terry Jan Reedy From brenNOSPAMbarn at NObrenSPAMbarn.net Tue Feb 1 14:32:16 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Tue, 1 Feb 2011 19:32:16 +0000 (UTC) Subject: Use the Source Luke References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> Message-ID: Tim Wintle wrote: > However I think the biggest changes that have probably happened > with python itself are: > > (1) More users for whom this is their first language. > (2) CS courses / training not teaching C (or pointer-based > languages). > > (2) is especially important IMO - under half of the python > developers I have regularly worked with would feel comfortable > reading C - so for the other half reading C source code probably > isn't going to help them understand exactly what's going on > (although in the long run it might help them a lot) I'd just like to note that (2) applies to me in spades. I'm not sure how many other people are in my position, but I use Python because I like how it works, and I do not want to use C because I find it insufferable. I quite frequently look at the source of Python modules, although more often third-party modules than the standard lib, but if I have to look at the C source of something I basically stop and find another solution (possibly abandoning Python altogether for that usage). I think, in general, the less anyone needs to know C even exists, the better for Python; likewise, the more that people have to mention the existence of C in a Python context, the worse for Python. This may be a somewhat extreme viewpoint, but that's my position. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From nagle at animats.com Tue Feb 1 14:35:48 2011 From: nagle at animats.com (John Nagle) Date: Tue, 01 Feb 2011 11:35:48 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: <4d486094$0$10557$742ec2ed@news.sonic.net> On 1/31/2011 2:17 PM, Kevin Walzer wrote: > It certainly would be interesting to see a fresh approach to IDLE... The future of "playing with Python" is probably Python in a browser window, of which there are several implementations. If you're doing anything serious, you're using a programmer's editor or an IDE. IDLE lives in a narrowing niche between those two points. Maybe it should be killed off. John Nagle From malaclypse2 at gmail.com Tue Feb 1 14:38:37 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 1 Feb 2011 14:38:37 -0500 Subject: How can I tell if I am inside a context manager? In-Reply-To: References: Message-ID: On Tue, Feb 1, 2011 at 1:38 PM, Gerald Britton wrote: > As you can see, the object has a '__enter__' method regardless of how > it was created. Whatever the test, it needs to return False in the > first case and True in the second case, without modifying the class > definition. > > I'm sorry, I completely misunderstood your question. I thought you were asking how you could tell if something provided a context manager. Based on the PEP[1], I don't see any generic way to tell if you are within a context manager. 1: http://www.python.org/dev/peps/pep-0343/ -- Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From patty at cruzio.com Tue Feb 1 14:44:20 2011 From: patty at cruzio.com (Patty) Date: Tue, 1 Feb 2011 11:44:20 -0800 Subject: multiple values for keyword argument Message-ID: Here is a list of the compiled personalities... #-- Moderates --# Patty ? 26 moderates 31 trolls, minions, sockpuppets, and or flamers 2 missing in action -------------------- = This community needs serious help! -- http://mail.python.org/mailman/listinfo/python-list How Embarrassing!! This caused great blushing!! Being categorized on a big email list...also not sure why I am not on the "#-- Complete Nobodys --#" list. You hit me right in my shy streak. I am really capable of a lot of participation on email lists and considering attending one of the BayPiggies in-person meetings and getting more involved. But I need to get smarter about Python programming first. This might _make_ me go MIA....yikes! Patty -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Tue Feb 1 14:56:38 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 01 Feb 2011 11:56:38 -0800 Subject: How can I tell if I am inside a context manager? In-Reply-To: References: Message-ID: <4D486576.6040900@stoneleaf.us> Gerald Britton wrote: > I'd like to know how (perhaps with the inspect module) I can tell if I > am running in a context manager. What's your use-case? ~Ethan~ From rantingrick at gmail.com Tue Feb 1 15:05:29 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 12:05:29 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> <4d486094$0$10557$742ec2ed@news.sonic.net> Message-ID: <87bb470f-0790-4210-82e9-8d587cf31f98@n36g2000pre.googlegroups.com> On Feb 1, 1:35?pm, John Nagle wrote: > On 1/31/2011 2:17 PM, Kevin Walzer wrote: > > > It certainly would be interesting to see a fresh approach to IDLE... > > The future of "playing with Python" is probably Python in a browser > window, of which there are several implementations. Hello John, I found skulpt which looks rather interesting. http://www.skulpt.org/ Why do we not have a version of this at python.org so people can get a feel for python right away. Ruby has that "Learn Ruby in 20 Minutes" thing and so should we. Do you have any links to projects such as this one that you like to share, John? From kb1pkl at aim.com Tue Feb 1 15:45:54 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 01 Feb 2011 15:45:54 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <87bb470f-0790-4210-82e9-8d587cf31f98@n36g2000pre.googlegroups.com> References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> <4d486094$0$10557$742ec2ed@news.sonic.net> <87bb470f-0790-4210-82e9-8d587cf31f98@n36g2000pre.googlegroups.com> Message-ID: <4D487102.5070003@aim.com> On 02/01/2011 03:05 PM, rantingrick wrote: > On Feb 1, 1:35 pm, John Nagle wrote: >> On 1/31/2011 2:17 PM, Kevin Walzer wrote: >> >>> It certainly would be interesting to see a fresh approach to IDLE... >> >> The future of "playing with Python" is probably Python in a browser >> window, of which there are several implementations. > > Hello John, > > I found skulpt which looks rather interesting. > > http://www.skulpt.org/ > > Why do we not have a version of this at python.org so people can get a > feel for python right away. Ruby has that "Learn Ruby in 20 Minutes" > thing and so should we. > > Do you have any links to projects such as this one that you like to > share, John? > http://people.csail.mit.edu/pgbovine/python/ Not quite an interpreter, and certainly has its limits, for example, it will only let you run so many steps before not letting you go on. I think it's a decent learning tool, but the visualisation is what makes it shine, IMO. That version uses python 2.5, there is also a version that uses python 3.1: http://netserv.ict.ru.ac.za/python3_viz/ From affdfsdfdsfsd at b.com Tue Feb 1 16:20:29 2011 From: affdfsdfdsfsd at b.com (Tracubik) Date: 01 Feb 2011 21:20:29 GMT Subject: how to get and search a html file from a website Message-ID: <4d48791d$0$1342$4fafbaef@reader2.news.tin.it> Hi all! i'm writing a notification program and i'm quite new to python. The program have to check every 5 minutes a particular website and alert me when a particular sentence ("user online") is in the html. i've thinked to use a text browser (lynx) to retrieve the html and parse the output in python as a normal text file. Do you have any better idea? thanks Medeo From paul.anton.letnes at gmail.com Tue Feb 1 16:27:23 2011 From: paul.anton.letnes at gmail.com (Paul Anton Letnes) Date: Tue, 01 Feb 2011 22:27:23 +0100 Subject: how to get and search a html file from a website In-Reply-To: <4d48791d$0$1342$4fafbaef@reader2.news.tin.it> References: <4d48791d$0$1342$4fafbaef@reader2.news.tin.it> Message-ID: Den 01.02.11 22.20, skrev Tracubik: > Hi all! > i'm writing a notification program and i'm quite new to python. > The program have to check every 5 minutes a particular website and alert > me when a particular sentence ("user online") is in the html. > i've thinked to use a text browser (lynx) to retrieve the html and parse > the output in python as a normal text file. > Do you have any better idea? > > thanks > Medeo Of course there is a pythonic way :-) >>> import urllib >>> urllib.urlretrieve('http://docs.python.org/tutorial/index.html', 'tut.html') Good luck, Paul. From beliavsky at aol.com Tue Feb 1 16:30:45 2011 From: beliavsky at aol.com (Beliavsky) Date: Tue, 1 Feb 2011 13:30:45 -0800 (PST) Subject: XEmacs output from Python Message-ID: The script name = raw_input("What is your name? ") print "Hello, ",name runs fine from the Windows prompt (cmd.exe), but when I run it in a shell buffer under XEmacs, I only see the text "What is your name? " AFTER I enter some text, so a run looks like this: H:\python>python xinput.py x What is your name? Hello, x Is there a workaround? Thanks. From kb1pkl at aim.com Tue Feb 1 16:33:16 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 01 Feb 2011 16:33:16 -0500 Subject: how to get and search a html file from a website In-Reply-To: <4d48791d$0$1342$4fafbaef@reader2.news.tin.it> References: <4d48791d$0$1342$4fafbaef@reader2.news.tin.it> Message-ID: <4D487C1C.9020204@aim.com> On 02/01/2011 04:20 PM, Tracubik wrote: > Hi all! > i'm writing a notification program and i'm quite new to python. > The program have to check every 5 minutes a particular website and alert > me when a particular sentence ("user online") is in the html. > i've thinked to use a text browser (lynx) to retrieve the html and parse > the output in python as a normal text file. > Do you have any better idea? > > thanks > Medeo urllib2 http://docs.python.org/howto/urllib2.html If you need fancy-shmancy parsing, look into: http://docs.python.org/library/htmlparser.html Or you can treat the returned site as a string and just search for that sentence. From prologic at shortcircuit.net.au Tue Feb 1 16:37:08 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 2 Feb 2011 07:37:08 +1000 Subject: how to get and search a html file from a website In-Reply-To: <4d48791d$0$1342$4fafbaef@reader2.news.tin.it> References: <4d48791d$0$1342$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, Feb 2, 2011 at 7:20 AM, Tracubik wrote: > Hi all! > i'm writing a notification program and i'm quite new to python. > The program have to check every 5 minutes a particular website and alert > me when a particular sentence ("user online") is in the html. > i've thinked to use a text browser (lynx) to retrieve the html and parse > the output in python as a normal text file. > Do you have any better idea? Assuming the website in question does not provide any useful APIs (sad), then a better approach is to use the urllib library in conjunction with lxml to parse the html in a sensible way (instead of just doing: if "foo" in s) cheers James -- -- James Mills -- -- "Problems are solved by method" From diesel at e-den.it Tue Feb 1 16:43:26 2011 From: diesel at e-den.it (Diesel) Date: Tue, 01 Feb 2011 21:43:26 GMT Subject: How to create an entry in the "Program menu" of Windows? Message-ID: <28%1p.9610$gy5.28412@twister1.libero.it> Hi, I'd like to add menu entry in the Program Menu as part of the installation of an application. Is it possible to do that from Python? Any examples or link? I have not been able to find anything with google... thanks in advance s/ From gelonida at gmail.com Tue Feb 1 16:44:20 2011 From: gelonida at gmail.com (Gelonida) Date: Tue, 01 Feb 2011 22:44:20 +0100 Subject: test: please ignore Message-ID: Somehow I can't post anymore to gmane. Would like to know why. From glicerinu at gmail.com Tue Feb 1 16:53:35 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Tue, 1 Feb 2011 13:53:35 -0800 (PST) Subject: DRY and static attribute for multiple classes. Message-ID: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> Hi all, I want to provide an encapsulated static attribute called _registry for several classes. I try to use inheritance in order to make it DRY: all classes inherit from a BaseClass that implements the _registry encapsulation. But with inheritance it doesn't work how I want, because a single instance of the _registry is shared between all of the inherited classes, and I want to have an independent _registry for every class. How can I do that without coping all the code in every class? Many Thanks!! From gelonida at gmail.com Tue Feb 1 17:01:15 2011 From: gelonida at gmail.com (Gelonida) Date: Tue, 01 Feb 2011 23:01:15 +0100 Subject: simplest way to create simple standalone wsgi server without import wsgi_lib.server In-Reply-To: <685d5386-d5bc-44aa-bb8c-2a395a458cde@i39g2000prd.googlegroups.com> References: <685d5386-d5bc-44aa-bb8c-2a395a458cde@i39g2000prd.googlegroups.com> Message-ID: On 02/01/2011 03:07 AM, Jean-Paul Calderone wrote: > On Jan 31, 5:28 pm, Gelonida wrote: >> Hi, >> >> Normally I use following code snippet to quickly test a wsgi module >> without a web server. >> >> import wsgi_lib.server >> wsgi_lib.server.run(application, port=port) >> >> However Now I'd like to test a small wsgi module on a rather old host >> ( Python 2.4.3 ) where I don't have means to update python. >> >> Is there any quick and easy code snippet / module, performing the same >> task as my above mentioned lines? >> >> Thanks in advance for any hints > > You didn't mention why you can't update Python, or if that means you > can't install new libraries either. However, if you have Twisted 8.2 > or newer, you can replace your snippet with this shell command: > > twistd -n web --port --wsgi Thanks Jean-Paul The problem is rather simple. The host in question is not 100% under my control. I can request to have packages installed if they're in the list of available packages. python 2.4 is part of it. twisted is not In the worst case I could request the installation of python virtualenv, the entire gcc tool chain and try to compile twisted, or wsgilib, but I wondered whether there isn't a simple pure python way of starting a wsgi server for test purposes. > > is the fully-qualified Python name of your application > object. So, for example if you have a module named "foo" that defines > an "application" name, you would pass "foo.application". > > Jean-Paul From rantingrick at gmail.com Tue Feb 1 17:06:11 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 1 Feb 2011 14:06:11 -0800 (PST) Subject: How to create an entry in the "Program menu" of Windows? References: <28%1p.9610$gy5.28412@twister1.libero.it> Message-ID: <07d850a7-531a-4870-ac54-6427bc4836fe@k38g2000vbn.googlegroups.com> On Feb 1, 3:43?pm, Diesel wrote: > I'd like to add menu entry in the Program Menu as part of the > installation of an application. Is it possible to do that from Python? Diesel your description is ambiguous at best, might we inquire that you elaborate a wee bit more? Is this "application" something that YOU created? If so what GUI library did you use? Can you show us some code or a small example? From gelonida at gmail.com Tue Feb 1 17:07:26 2011 From: gelonida at gmail.com (Gelonida) Date: Tue, 01 Feb 2011 23:07:26 +0100 Subject: test: please ignore In-Reply-To: References: Message-ID: On 02/01/2011 10:44 PM, Gelonida wrote: > Somehow I can't post anymore to gmane. > > Would like to know why. > Now this message arrived. So it seems to work again, though with quite some heavy delay. From anton.list at gmail.com Tue Feb 1 17:20:30 2011 From: anton.list at gmail.com (AD.) Date: Tue, 1 Feb 2011 14:20:30 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> Message-ID: On Feb 2, 4:14?am, rantingrick wrote: > On Feb 1, 8:27?am, Jean-Michel Pichavant > wrote: > > > In a more serious way, just count the people who second your > > prosposition. It's around 0. It is usually a good sign that you're > > wrong. This rule kinda applies to anyone, don't take it personnaly. > > Well your statment completely ignores the silent majority. Are you > telling me that this sloth of trolls, minions, and flamers that have > so far replied are represetative of this fine community. As a member of this silent majority - we care less about IDLEs code quality than all the others that did actually care enough to even reply to you. Now stop your annoying trolling and either start working on your IDLE fork or shut up. Nobody else who agrees with you (there might be someone out there) has been ever been motivated enough to initiate this work by themselves, so unless YOU start it - it probably is never going to happen. Once it is underway you might attract some other people interested in helping to refactor or recode IDLE - but you won't know that unless you start work on it. But I think we all know exactly what you are actually going to keep doing though. -- Cheers Anton From calderone.jeanpaul at gmail.com Tue Feb 1 17:36:45 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 1 Feb 2011 14:36:45 -0800 (PST) Subject: simplest way to create simple standalone wsgi server without import wsgi_lib.server References: <685d5386-d5bc-44aa-bb8c-2a395a458cde@i39g2000prd.googlegroups.com> Message-ID: <5b976c23-7154-4464-844b-08b39999016e@h19g2000prh.googlegroups.com> On Feb 1, 2:01?pm, Gelonida wrote: > On 02/01/2011 03:07 AM, Jean-Paul Calderone wrote: > > > > > On Jan 31, 5:28 pm, Gelonida wrote: > >> Hi, > > >> Normally I use following code snippet to quickly test a wsgi module > >> without a web server. > > >> import wsgi_lib.server > >> wsgi_lib.server.run(application, port=port) > > >> However Now I'd like to test a small wsgi module on a rather old host > >> ( Python 2.4.3 ) where I don't have means to update python. > > >> Is there any quick and easy code snippet / module, performing the same > >> task as my above mentioned lines? > > >> Thanks in advance for any hints > > > You didn't mention why you can't update Python, or if that means you > > can't install new libraries either. ?However, if you have Twisted 8.2 > > or newer, you can replace your snippet with this shell command: > > > ? ? twistd -n web --port --wsgi > > Thanks Jean-Paul > > The problem is rather simple. The host in question is not 100% under my > control. I can request to have packages installed if they're in the list > of available packages. > > python 2.4 is part of it. twisted is not > > In the worst case I could request the installation of python virtualenv, > the entire gcc tool chain and try to compile twisted, > or wsgilib, but I wondered whether there isn't a simple pure python way > of starting a wsgi server for test purposes. > You may be able to install Twisted (or even wsgilib) in your home directory. For example, the command: python setup.py --prefix ~/.local will install Twisted (or maybe wsgilib) in ~/.local/lib/python2.4/site- packages/. Add that to your PYTHONPATH (eg in your .bashrc) and you're basically all set. Also, though Twisted has some extension modules, they're optional. So you should be fine without a compiler, *except* that distutils doesn't cope so well with certain cases. If you find "setup.py install" fails for some reason, you can also just add the unpacked source directory to PYTHONPATH and run it in-place without installation. Jean-Paul From __peter__ at web.de Tue Feb 1 18:11:48 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 Feb 2011 00:11:48 +0100 Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> Message-ID: Marc Aymerich wrote: > Hi all, > I want to provide an encapsulated static attribute called _registry > for several classes. > > I try to use inheritance in order to make it DRY: all classes inherit > from a BaseClass that implements the _registry encapsulation. But with > inheritance it doesn't work how I want, because a single instance of > the _registry is shared between all of the inherited classes, and I > want to have an independent _registry for every class. > > How can I do that without coping all the code in every class? If you want to go fancy use a metaclass: >>> class Base(object): ... class __metaclass__(type): ... def __init__(self, *args): ... type.__init__(self, *args) ... self.per_class = [] ... >>> class A(Base): pass ... >>> A().per_class is A().per_class True >>> class B(Base): pass ... >>> B().per_class is B().per_class True >>> A().per_class is B().per_class False From anikom15 at gmail.com Tue Feb 1 18:22:46 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Tue, 01 Feb 2011 15:22:46 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: <1296602566.477.1.camel@localhost.localdomain> What does Chopin have to do with IDLE? And can you put me on your troll group? It looks like a pretty fun bunch. On Tue, 2011-02-01 at 09:26 -0800, rantingrick wrote: > On Feb 1, 10:29 am, "Littlefield, Tyler" wrote: > > > I hope everyone will > > excuse me now, I must dash off to slit my wrists in a tub of warm water > > and listen to Free Bird, > > Free Bird! hmm, I would have chosen Chopin's nocturne 48-1 or 72-1 if > i was feeling rather melancholy at the moment. Then there is always > the funeral march if you really want to lay it on thick. However the > march does have a rather lengthy "hopeful" section that may make you > give second thoughts. Or perhaps the Berceuse in D-flat Major as a > final glorious celebration of life as one journeys beyond the edge of > transcendence. If there is a heaven it must sound like this... > > http://il.youtube.com/watch?v=8TQ-AXJZqtg > > ...only a man who suffered so greatly can know what true beauty is. > RIP Chopin. > > If you're going to met your end it should be at least to a piece that > is truly timeless -- not some reefer+jack induced rockabilly ballad! -------------- next part -------------- An HTML attachment was scrubbed... URL: From gelonida at gmail.com Tue Feb 1 18:30:31 2011 From: gelonida at gmail.com (Gelonida) Date: Wed, 02 Feb 2011 00:30:31 +0100 Subject: simplest way to create simple standalone wsgi server without import wsgi_lib.server In-Reply-To: <5b976c23-7154-4464-844b-08b39999016e@h19g2000prh.googlegroups.com> References: <685d5386-d5bc-44aa-bb8c-2a395a458cde@i39g2000prd.googlegroups.com> <5b976c23-7154-4464-844b-08b39999016e@h19g2000prh.googlegroups.com> Message-ID: On 02/01/2011 11:36 PM, Jean-Paul Calderone wrote: >> >>> twistd -n web --port --wsgi >> >> >> The problem is rather simple. The host in question is not 100% under my >> control. I can request to have packages installed if they're in the list >> of available packages. >> >> python 2.4 is part of it. twisted is not >> > > You may be able to install Twisted (or even wsgilib) in your home > directory. For example, the command: > > python setup.py --prefix ~/.local > > will install Twisted (or maybe wsgilib) in ~/.local/lib/python2.4/site- > packages/. Add that to your PYTHONPATH (eg in your .bashrc) and > you're basically all set. Also, though Twisted has some extension > modules, they're optional. So you should be fine without a compiler, > *except* that distutils doesn't cope so well with certain cases. If > you find "setup.py install" fails for some reason, you can also just > add the unpacked source directory to PYTHONPATH and run it in-place > without installation. > Thanks a lot you gave me some new ideas. I made first attempts with virtualenv and easy_install no module with C-code can be installed (some issue with tool chain) - wsgilib installation failed therefore - twisted installation failed therefore I untarred twisted and tried to run twistd. it complains about missing zope.interface installing of zope.interface fails also with gcc error. It seems I am currently stuck until I find a simplistic python only solution for quick standalone wsgi_module tests. From gelonida at gmail.com Tue Feb 1 18:31:57 2011 From: gelonida at gmail.com (Gelonida) Date: Wed, 02 Feb 2011 00:31:57 +0100 Subject: PyQT: QWebView with custom QNetworkAccessManager Message-ID: Hi, I would like to subclass QNetworkAccessManager and create a subclass of QWebView, that will use the subclassed QNetworkAccessManager for all accesses. Is this possible? I have really no idea when and how I could achieve this. Thanks in advance for any suggestions / pointers From torriem at gmail.com Tue Feb 1 18:43:12 2011 From: torriem at gmail.com (Michael Torrie) Date: Tue, 01 Feb 2011 16:43:12 -0700 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> Message-ID: <4D489A90.9030509@gmail.com> On 02/01/2011 08:26 AM, Noah Hall wrote: > On Tue, Feb 1, 2011 at 3:14 PM, rantingrick wrote: >> #-- Embedded Trolls and Minions --# > These people, including myself, aren't trolls nor minions. They just > don't agree with you. I strongly disagree with rr and find him to be an egotistical troll who likes to hear the sound of his own, er, typing. Hence I'm disappointed that I'm not on his list. His posts really cause me to be conflicted. On the one hand they are fascinating in the train-wreck sense, on the other hand my replying to this perpetuates his ranting. Sigh. Consider yourself fed, rr. From torriem at gmail.com Tue Feb 1 18:44:12 2011 From: torriem at gmail.com (Michael Torrie) Date: Tue, 01 Feb 2011 16:44:12 -0700 Subject: How to create an entry in the "Program menu" of Windows? In-Reply-To: <28%1p.9610$gy5.28412@twister1.libero.it> References: <28%1p.9610$gy5.28412@twister1.libero.it> Message-ID: <4D489ACC.6010909@gmail.com> On 02/01/2011 02:43 PM, Diesel wrote: > I'd like to add menu entry in the Program Menu as part of the > installation of an application. Is it possible to do that from Python? > > Any examples or link? I have not been able to find anything with > google... Use an installer program like nsis to create an installer package from your python app. It can do all those kinds of things, and clean up after the program is uninstalled. From alex.kapps at web.de Tue Feb 1 18:52:25 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Wed, 02 Feb 2011 00:52:25 +0100 Subject: How to create an entry in the "Program menu" of Windows? In-Reply-To: <28%1p.9610$gy5.28412@twister1.libero.it> References: <28%1p.9610$gy5.28412@twister1.libero.it> Message-ID: <4D489CB9.6010308@web.de> On 01.02.2011 22:43, Diesel wrote: > > Hi, > > I'd like to add menu entry in the Program Menu as part of the > installation of an application. Is it possible to do that from Python? > > Any examples or link? I have not been able to find anything with > google... > > thanks in advance > s/ > AFAIK, the startmenu entries are just .lnk files, placed either in the "All Users" or "Some Specific User" Startmenu directory. I only have a German XP and can't boot it to test at the moment, so I can't give more details, but there are surely registry entries to find the Startmenu location for the current user or for "All Users". See http://codesnippets.joyent.com/posts/show/529 for an example how to place .lnk files. However, for real deployment, you probably want to use a real installer framework like NSIS for example. HTH From gnarlodious at gmail.com Tue Feb 1 19:11:51 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 1 Feb 2011 16:11:51 -0800 (PST) Subject: Print docstrings to shell Message-ID: Can I run a script in bash and print out its docstrings to the bash shell? I tried this at the end: print(help(__file__)) Runnig the script: python ~/Sites/Sectrum/Harmonics.py but all it spit out was: no Python documentation found for '~/Sites/Sectrum/Harmonics.py' However in the interactive shell it prints out the class structure nicely. What I really want to see is this output in the bash window. -- Gnarlie From anikom15 at gmail.com Tue Feb 1 19:25:35 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Tue, 01 Feb 2011 16:25:35 -0800 Subject: How to create an entry in the "Program menu" of Windows? In-Reply-To: <28%1p.9610$gy5.28412@twister1.libero.it> References: <28%1p.9610$gy5.28412@twister1.libero.it> Message-ID: <1296606335.477.6.camel@localhost.localdomain> distutils can do this with a post-install script. See the distutils documentation. This is a script I wrote that did this (and other stuff): import sys import os if sys.argv[1] == '-install': # Append .py to scripts os.rename(os.path.join(sys.prefix, 'Scripts', 'anikom15'), os.path.join(sys.prefix, 'Scripts', 'anikom15.py')) file_created(os.path.join(sys.prefix, 'Scripts', 'anikom15.py')) # Create desktop and start menu shortcuts desktop = get_special_folder_path("CSIDL_COMMON_DESKTOPDIRECTORY") startmenu = get_special_folder_path("CSIDL_COMMON_STARTMENU") create_shortcut(os.path.join(sys.prefix, 'Scripts', 'anikom15.py'), "Launch Anikom15's Computer Game", os.path.join(desktop, 'Anikom15.lnk'), '', '', os.path.join(sys.prefix, 'Icons', 'anikom15.ico')) file_created(os.path.join(desktop, 'Anikom15.lnk')) create_shortcut(os.path.join(sys.prefix, 'Scripts', 'anikom15.py'), "Anikom15's Computer Game", os.path.join(startmenu, 'Anikom15.lnk'), '', '', os.path.join(sys.prefix, 'Icons', 'anikom15.ico')) file_created(os.path.join(startmenu, 'Anikom15.lnk')) elif sys.argv[1] == '-remove': pass On Tue, 2011-02-01 at 21:43 +0000, Diesel wrote: > Hi, > > I'd like to add menu entry in the Program Menu as part of the > installation of an application. Is it possible to do that from Python? > > Any examples or link? I have not been able to find anything with > google... > > thanks in advance > s/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andre.roberge at gmail.com Tue Feb 1 19:30:47 2011 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Tue, 1 Feb 2011 16:30:47 -0800 (PST) Subject: Print docstrings to shell In-Reply-To: Message-ID: On Tuesday, February 1, 2011 8:11:51 PM UTC-4, Gnarlodious wrote: > Can I run a script in bash and print out its docstrings to the bash > shell? I tried this at the end: > > print(help(__file__)) > > Runnig the script: > python ~/Sites/Sectrum/Harmonics.py > > but all it spit out was: > > no Python documentation found for '~/Sites/Sectrum/Harmonics.py' > > However in the interactive shell it prints out the class structure > nicely. What I really want to see is this output in the bash window. > > -- Gnarlie Try the following: ============test.py====== import pydoc '''this is a test''' class A(object): '''docstring''' pass print(pydoc.help(__file__[:-3])) ============= python test.py Andr? From sigzero at gmail.com Tue Feb 1 19:42:04 2011 From: sigzero at gmail.com (Robert) Date: Tue, 1 Feb 2011 19:42:04 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: On 2011-02-01 10:54:26 -0500, Terry Reedy said: > On 2/1/2011 12:13 AM, rantingrick wrote: >> On Jan 31, 4:17 pm, Kevin Walzer wrote: >>> Rick, > >> Yes. IDLE is first and foremost a tool to get work done. However we >> should not ignore the fact that IDLE could also be a great learning >> resource for Tkinter GUI's and other subjects. Why not clean up the >> code base? We could start small. First, move the custom widgets like >> textView, Tabbedpages, FindDialog, ReplaceDialog, and TreeWidget into >> the lib-tk for others to use more freely. Then we can modify the >> "event robbers" CallTips, ParenMatch, and ColorDelegator. > > Perhaps, after the repository moves from svn to hg, some 'we' will. > Maybe by then, you will have had your fun and be ready to work. Maybe > Kevin would help a bit. If he does not, I think I might. Is there a timeline for the move? > > Such a project would be carried out on the tracker and idle-sig mailing > list. Normal decorum would be required -- no ranting or insulting. The > first thing to do, in my opinion, is to review existing patches on the > tracker. > >> Well some changes and improvements can be made to the UI as well. > > There is patch on the tracker, by G. Polo, as I remember, to replace tk > widgets with the newer themed ttk widgets. It needs to be reviewed and > tested. To make a big change (or proceed with any refactoring) better > automated testing would be very useful. +1 for the UI update +1 for more tests -- Robert From kb1pkl at aim.com Tue Feb 1 19:46:02 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Tue, 01 Feb 2011 19:46:02 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> Message-ID: <4D48A94A.3040305@aim.com> On 02/01/2011 07:42 PM, Robert wrote: > On 2011-02-01 10:54:26 -0500, Terry Reedy said: > >> On 2/1/2011 12:13 AM, rantingrick wrote: >>> On Jan 31, 4:17 pm, Kevin Walzer wrote: >>>> Rick, >> >>> Yes. IDLE is first and foremost a tool to get work done. However we >>> should not ignore the fact that IDLE could also be a great learning >>> resource for Tkinter GUI's and other subjects. Why not clean up the >>> code base? We could start small. First, move the custom widgets like >>> textView, Tabbedpages, FindDialog, ReplaceDialog, and TreeWidget into >>> the lib-tk for others to use more freely. Then we can modify the >>> "event robbers" CallTips, ParenMatch, and ColorDelegator. >> >> Perhaps, after the repository moves from svn to hg, some 'we' will. >> Maybe by then, you will have had your fun and be ready to work. Maybe >> Kevin would help a bit. > > If he does not, I think I might. Is there a timeline for the move? > I would help with such a project as well, given the opportunity. From gnarlodious at gmail.com Tue Feb 1 20:05:28 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 1 Feb 2011 17:05:28 -0800 (PST) Subject: Print docstrings to shell References: Message-ID: On Feb 1, 5:30?pm, Andr? Roberge wrote: > ============test.py====== > import pydoc > > '''this is a test''' > > class A(object): > ? ? ? ? '''docstring''' > ? ? ? ? pass > > print(pydoc.help(__file__[:-3])) > ============= > > python test.py OK that works, but only if I cd into the folder of the script. If I run it from ~ I get the same error. How to get around that prob? -- Gnarlie From andre.roberge at gmail.com Tue Feb 1 20:21:48 2011 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Tue, 1 Feb 2011 17:21:48 -0800 (PST) Subject: Print docstrings to shell In-Reply-To: Message-ID: On Tuesday, February 1, 2011 9:05:28 PM UTC-4, Gnarlodious wrote: > On Feb 1, 5:30?pm, Andr? Roberge wrote: > > > ============test.py====== > > import pydoc > > > > '''this is a test''' > > > > class A(object): > > ? ? ? ? '''docstring''' > > ? ? ? ? pass > > > > print(pydoc.help(__file__[:-3])) > > ============= > > > > python test.py > > > OK that works, but only if I cd into the folder of the script. If I > run it from ~ I get the same error. How to get around that prob? > > -- Gnarlie ======= import pydoc import os import sys '''this is a test''' class A(object): '''docstring''' pass _path, _file_name = os.path.split(__file__) _module_name = _file_name[:-3] sys.path.append(_path) pydoc.help(_module_name) ===== Note: I've included an underscore in variables names so that they would not appear. Note 2: for some reason, which I do not understand, it shows the help twice (i.e. I have to hit "q" twice to make it go away). Sorry that I can not help with this. Andr? From gelonida at gmail.com Tue Feb 1 20:37:06 2011 From: gelonida at gmail.com (Gelonida) Date: Wed, 02 Feb 2011 02:37:06 +0100 Subject: PyQT: QWebView with custom QNetworkAccessManager In-Reply-To: References: Message-ID: On 02/02/2011 12:31 AM, Gelonida wrote: > Hi, > > I would like to subclass QNetworkAccessManager and > create a subclass of QWebView, that will use the subclassed > QNetworkAccessManager for all accesses. > > Is this possible? > I have really no idea when and how I could achieve this. > > Thanks in advance for any suggestions / pointers > Well I answer my own question. In fact my first experiments failed horribly due to a tiny PyQt detail. I expected that, the variable new_manager does not have to be persistent. I naively assumed, that a call to setNetworkAccessManager() would keep a reference to new_manager and thus avoid its destruction this does not seem to be the case. Below an example of how to create a QQWebview with a custom NetworkAccessManager import sys import PyQt4.QtGui as QtGui import PyQt4.QtCore as QtCore import PyQt4.QtWebKit as QtWebKit from PyQt4.QtNetwork import QNetworkAccessManager class MyNetworkAccessManager(QNetworkAccessManager): def __init__(self, old_manager): QNetworkAccessManager.__init__(self) self.setCache(old_manager.cache()) self.setCookieJar(old_manager.cookieJar()) self.setProxy(old_manager.proxy()) self.setProxyFactory(old_manager.proxyFactory()) def createRequest(self, operation, request, data): print "mymanager handles ", request.url() return QNetworkAccessManager.createRequest( self, operation, request, data) def set_new_manager(web): global new_manager # if this line is commented I will se old_manager = web.page().networkAccessManager() new_manager = MyNetworkAccessManager(old_manager) web.page().setNetworkAccessManager(new_manager) app = QtGui.QApplication(sys.argv) web = QtWebKit.QWebView() set_new_manager() web.setUrl( QtCore.QUrl("http://www.google.com") ) web.show() sys.exit(app.exec_()) From andre.roberge at gmail.com Tue Feb 1 20:53:11 2011 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Tue, 1 Feb 2011 17:53:11 -0800 (PST) Subject: Print docstrings to shell In-Reply-To: Message-ID: <4cac3f59-7479-42d7-8e71-199480abf85c@glegroupsg2000goo.googlegroups.com> On Tuesday, February 1, 2011 9:21:48 PM UTC-4, Andr? Roberge wrote: SNIP > > ======= > import pydoc > import os > import sys > > '''this is a test''' > > class A(object): > '''docstring''' > pass > > _path, _file_name = os.path.split(__file__) > _module_name = _file_name[:-3] > sys.path.append(_path) > pydoc.help(_module_name) > ===== > Actually, one does not need to import pydoc; using help() without importing seems to work just as well (or as badly, as it displays it twice...) Andr? > Note: I've included an underscore in variables names so that they would not appear. > Note 2: for some reason, which I do not understand, it shows the help twice (i.e. I have to hit "q" twice to make it go away). Sorry that I can not help with this. > > Andr? From research at johnohagan.com Tue Feb 1 21:41:11 2011 From: research at johnohagan.com (John O'Hagan) Date: Wed, 2 Feb 2011 02:41:11 +0000 Subject: Reassign or discard Popen().stdout from a server process In-Reply-To: <201102011526.39023.mail@johnohagan.com> References: <201102010830.20110.mail@johnohagan.com> <201102011526.39023.mail@johnohagan.com> Message-ID: <201102020241.12018.research@johnohagan.com> On Tue, 1 Feb 2011, John O'Hagan wrote: > > So far my best bet seems to be closing stdin, which doesn't seem very > clean, but it does what I want and seems to be just as fast as using > stdin=open(os.devnull) in the Popen call in the first place. ...and both references to stdin above should have been to stdout (I really shouldn't post last thing at night). > Thanks, > > John From pavlovevidence at gmail.com Tue Feb 1 21:53:09 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 1 Feb 2011 18:53:09 -0800 (PST) Subject: Print docstrings to shell References: Message-ID: <72ef3b80-34c2-44d5-ac5e-7a5ab198cab0@24g2000yqa.googlegroups.com> On Feb 1, 4:11?pm, Gnarlodious wrote: > Can I run a script in bash and print out its docstrings to the bash > shell? I tried this at the end: > > print(help(__file__)) > > Runnig the script: > python ~/Sites/Sectrum/Harmonics.py > > but all it spit out was: > > no Python documentation found for '~/Sites/Sectrum/Harmonics.py' > > However in the interactive shell it prints out the class structure > nicely. What I really want to see is this output in the bash window. The help() function prints the documentation itself itself (piping it to a pager if possible). It doesn't return the help text. If that's what you want, then probably the most foolproof way is: help(sys.modules[__name__]) This'll work whether it's a module or script. If you just want to print the documentation and bypass the pager, then I think something like this will do it: import pydoc print pydoc.render_doc(sys.modules[__name__]) Carl Banks From python at rcn.com Tue Feb 1 22:35:40 2011 From: python at rcn.com (Raymond Hettinger) Date: Tue, 1 Feb 2011 19:35:40 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: <350a77f3-3c63-4a9a-8d33-ffca6712df4c@s29g2000pra.googlegroups.com> On Jan 31, 9:39?am, rantingrick wrote: > IDLE: cornucopia ... > These are just the top of the list. The peak of a huge iceberg that > threatens to sink the community in the arms of chaos never to return. That being said, I've taught a lot of people Python using IDLE. It's a surprisingly productive environment and has a near-zero learning curve. > I am beginning to believe that this community is either made of > amateurs due to this lackluster code in the stdlib. However it could > be that the folks are really professional and refuse to work on such a > horrible code base (which i understand). I am going with the latter. Patches are welcome :-) From anikom15 at gmail.com Tue Feb 1 22:48:15 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Tue, 01 Feb 2011 19:48:15 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: <1296618495.6892.0.camel@localhost.localdomain> http://www.youtube.com/watch?v=z5jKMEB4hHE On Tue, 2011-02-01 at 10:23 -0800, rantingrick wrote: > On Feb 1, 11:52 am, Red John wrote: > > > Go away. You are easily one of the worst (and definitely most > > annoying) person I've encountered in person or online, which is saying > > something because I used to frequent 4chan. > > Hmm, that coming from someone who has two posts in this group. And the > last he posted was a year ago! Alright, let me add you to the proper > category... > > py> troll_group.append("Red John") -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnarlodious at gmail.com Tue Feb 1 22:59:24 2011 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 1 Feb 2011 19:59:24 -0800 (PST) Subject: Print docstrings to shell References: <72ef3b80-34c2-44d5-ac5e-7a5ab198cab0@24g2000yqa.googlegroups.com> Message-ID: <9e83af48-361a-4147-a734-2c03d4401b90@8g2000prt.googlegroups.com> Thank you for the help, I learned a few things. The Andr? solution renders the colors but needs q-q to quit. The Carl solution 1 prints colors and requires q to quit. The Carl solution 2 prints colorlessly, it looks good for exporting to a file. Everything I need. -- Gnarlie http://Gnarlodious.com From panupatc at gmail.com Tue Feb 1 23:35:35 2011 From: panupatc at gmail.com (Panupat Chongstitwattana) Date: Wed, 2 Feb 2011 11:35:35 +0700 Subject: Adding Asian text error with IIS Message-ID: I created a very simple script, testing it out with web browser. # -*- coding: utf-8 -*- import sys sys.getdefaultencoding() f = '?' print "Content-Type: text/plain;charset=utf-8" print f The moment I have an Asian text in my file (without doing anything to it at all) I always get a 502 error - web server received an invalid response. The script prints out just fine if I use python own IDLE however. The file was utf-8 encoded and setdefaultencoding is also utf-8. Testing out on windows server 2008 R2 IIS 7.5. Any help greatly appreciate! -------------- next part -------------- An HTML attachment was scrubbed... URL: From gwchamb at gwcmail.com Tue Feb 1 23:36:27 2011 From: gwchamb at gwcmail.com (Gary Chambers) Date: Tue, 1 Feb 2011 23:36:27 -0500 (EST) Subject: Perl Hacker, Python Initiate Message-ID: All, Given the following Perl script: #!/usr/bin/perl %dig = ( solaris => "/usr/sbin/dig", linux => "/usr/bin/dig", darwin => "/usr/bin/dig" ); $DIG = $dig{"$^O"}; $DOMAIN = "example.com"; $DNS = "ns.example.com"; $DIGCMD = qq/$DIG \@$DNS $DOMAIN axfr/; open DIG, "$DIGCMD|" or die "$DIG: $!\n"; while () { next if (/^;/); # Skip any comments # If we match a CNAME record, we have an alias to something. # $1 = alias (CNAME), $2 = canonical hostname if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.${DOMAIN}\.$/) { # Push an alias (CNAME) onto an array indexed on canonical hostname push(@{$cnames{$2}}, $1); } # Here's a standard A (canonical hostname) record # $1 = canonical hostname, $2 = IPv4 address if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*A\s+(\S+)$/) { $ip{$1} = $2; } } close DIG; # Format and display it like niscat hosts: # canonicalHostname alias1 [alias2 aliasN] ipAddress for $host (sort keys %ip) { print "$host "; if (defined(@{$cnames{$host}})) { print join(' ', @{$cnames{$host}}); print " "; } print "$ip{$host}\n"; } exit 0; Will someone please provide some insight on how to accomplish that task in Python? I am unable to continually (i.e. it stops after displaying a single line) loop through the output while testing for the matches on the two regular expressions. Thank you. -- Gary Chambers From clp2 at rebertia.com Tue Feb 1 23:48:56 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 1 Feb 2011 20:48:56 -0800 Subject: Perl Hacker, Python Initiate In-Reply-To: References: Message-ID: On Tue, Feb 1, 2011 at 8:36 PM, Gary Chambers wrote: > All, > > Given the following Perl script: > Will someone please provide some insight on how to accomplish that task in > Python? ?I am unable to continually (i.e. it stops after displaying a single > line) loop through the output while testing for the matches on the two > regular expressions. ?Thank you. What's your Python translation attempt look like? Cheers, Chris -- http://blog.rebertia.com From ben+python at benfinney.id.au Tue Feb 1 23:56:53 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 02 Feb 2011 15:56:53 +1100 Subject: Perl Hacker, Python Initiate References: Message-ID: <87sjw7vxt6.fsf@benfinney.id.au> Gary Chambers writes: > Given the following Perl script: [?] > > Will someone please provide some insight on how to accomplish that > task in Python? I am unable to continually (i.e. it stops after > displaying a single line) loop through the output while testing for > the matches on the two regular expressions. Thank you. Insight will be easier to provide once we see your Python code. -- \ ?In the long run, the utility of all non-Free software | `\ approaches zero. All non-Free software is a dead end.? ?Mark | _o__) Pilgrim, 2006 | Ben Finney From sohel807 at gmail.com Wed Feb 2 00:36:50 2011 From: sohel807 at gmail.com (Akand Islam) Date: Tue, 1 Feb 2011 21:36:50 -0800 (PST) Subject: wxPython's "Print" Help Message-ID: <8ad59b6e-8f69-4a90-8de2-9b3ac2e1438a@n18g2000vbq.googlegroups.com> I can print whatever I want (definitely texts) by using following "Printer" class. However, it prints only in Black and White mode regardless original color of texts. Is there any way I can print color texts? ===================================================================== #License: MIT import wx from wx import Printout, PrintData, PAPER_LETTER, PrintDialogData from wx import Printer as wxPrinter, MessageBox, PrintPreview, PrintDialog def GetErrorText(): "Put your error text logic here. See Python Cookbook for a useful example of error text." return "Some error occurred." class Printer(Printout): def __init__(self, frame): "Prepares the Printing object. Note: change current_y for 1, 1.5, 2 spacing for lines." Printout.__init__(self) self.printer_config = PrintData() self.printer_config.SetPaperId(PAPER_LETTER) self.frame = frame self.doc_text = '' self.doc_name = '' self.current_y = 50 #y should be either (15, 22, 30) if self.current_y == 15: self.num_lines_per_page = 50 elif self.current_y == 22: self.num_lines_per_page = 35 else: self.num_lines_per_page = 60 def Print(self, text, doc_name): "Prints the given text. Currently doc_name logic doesn't exist. E.g. might be useful for a footer.." self.doc_text = text self.doc_name = doc_name pdd = PrintDialogData() pdd.SetPrintData(self.printer_config) printer = wxPrinter(pdd) if not printer.Print(self.frame,self): MessageBox("Unable to print the document.") else: self.printer_config = PrintData(printer.GetPrintDialogData().GetPrintData()) def PreviewText(self, text, doc_name): "This function displays the preview window for the text with the given header." try: self.doc_name = doc_name self.doc_text = text #Destructor fix by Peter Milliken -- print1 = Printer(self.frame, text = self.doc_text) print2 = Printer(self.frame, text = self.doc_text) preview = PrintPreview(print1, print2, self.printer_config) #preview = PrintPreview(self,self,self.printer_config) if not preview.Ok(): MessageBox("Unable to display preview of document.") return preview_window = PreviewFrame(preview, self.frame, \ "Print Preview - %s" % doc_name) preview_window.Initialize() preview_window.SetPosition(self.frame.GetPosition()) preview_window.SetSize(self.frame.GetSize()) preview_window.MakeModal(True) preview_window.Show(True) except: MessageBox(GetErrorText()) def PageSetup(self): """ This function handles displaying the Page Setup window and retrieving the user selected options. It's been updated to use the new style Windows, which allow more options to be configured. """ config_dialog = wxPageSetupDialog(self.frame) config_dialog.GetPageSetupData() config_dialog.ShowModal() self.printer_config = config_dialog.GetPageSetupData() config_dialog.Destroy() def OnBeginDocument(self,start,end): "Do any end of document logic here." self.base_OnBeginDocument(start,end) def OnEndDocument(self): "Do any end of document logic here." self.base_OnEndDocument() def OnBeginPrinting(self): "Do printing initialization logic here." self.base_OnBeginPrinting() def OnEndPrinting(self): "Do any post printing logic here." self.base_OnEndPrinting() def OnPreparePrinting(self): "Do any logic to prepare for printing here." self.base_OnPreparePrinting() def HasPage(self, page_num): "This function is called to determine if the specified page exists." return len(self.GetPageText(page_num)) > 0 def GetPageInfo(self): """ This returns the page information: what is the page range available, and what is the selected page range. Currently the selected page range is always the available page range. This logic should be changed if you need greater flexibility. """ minPage = 1 maxPage = int(len(self.doc_text.split('\n'))/ self.num_lines_per_page) + 1 fromPage, toPage = minPage, maxPage return (minPage,maxPage,fromPage,toPage) def OnPrintPage(self, page_num): "This function / event is executed for each page that needs to be printed." dc = self.GetDC() x,y = 25, self.current_y if not self.IsPreview(): y *=4 line_count = 1 for line in self.GetPageText(page_num): dc.DrawText(line, x, y*line_count) line_count += 1 return True def GetPageText(self, page_num): "This function returns the text to be displayed for the given page number." lines = self.doc_text.split('\n') lines_for_page = lines[(page_num -1)*self.num_lines_per_page: page_num*(self.num_lines_per_page-1)] return lines_for_page ## End of codes Thanks in advance. -- Akand From ansuman.python at gmail.com Wed Feb 2 01:26:11 2011 From: ansuman.python at gmail.com (Ansuman Bebarta) Date: Tue, 1 Feb 2011 22:26:11 -0800 (PST) Subject: Classic asp registered with python in IIS 7 Message-ID: I had a website which used IIS 6 to call classic asp pages. The asp pages called python script and the python pages was doing all the operations. Now I am using IIS7 in windows7 and while running my websites I am getting HTTP/1.1 500 Server Error. I have done following steps but no luck. I have installed asp in IIS7 and I have registered asp with python by running pyscript.py (using python 2.7). Let me tell you that I wrote a simple classic asp code and it worked in IIS7.The asp code was - <%response.write("Hello World")%> I wrote a cgi with python and it worked with IIS7.The python script for cgi was - print "Content-Type: text/plain;charset=utf-8" - print "Hello World!" But when I wrote another classic asp containing python code it didnt worked and I got same HTTP/1.1 500 Server Error. The code for asp with python was -<%@Language=Python%> -<% -x="Hello" -response.write(x) -%> From alexandra at compulab.co.il Wed Feb 2 01:40:33 2011 From: alexandra at compulab.co.il (Sandy Oz) Date: Wed, 02 Feb 2011 08:40:33 +0200 Subject: Help with python-twain module Message-ID: <4D48FC61.3050704@compulab.co.il> Hello everyone, Really need help with the python-twain module. I installed the module for python 2.6 on a win-xp 32bit machine. I ran the demo app and got a python core crash when calling SourceManager.OpenSource(). I've managed to run the scanner I'm using on a Linux machine with python-imaging-sane module, but ran into problems when switching to windows. Any help will be greatly appreciated, Thanks, Sandy From pavlovevidence at gmail.com Wed Feb 2 02:52:02 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 1 Feb 2011 23:52:02 -0800 (PST) Subject: Perl Hacker, Python Initiate References: Message-ID: <793a3ffd-95b5-48b5-9b3c-f13cb7c431d2@u24g2000prn.googlegroups.com> On Feb 1, 8:36?pm, Gary Chambers wrote: > open DIG, "$DIGCMD|" or die "$DIG: $!\n"; > while () { > Will someone please provide some insight on how to accomplish that task in > Python? ?I am unable to continually (i.e. it stops after displaying a single > line) loop through the output while testing for the matches on the two > regular expressions. ?Thank you. You may have called read() instead of readlines(). Carl Banks From phil at riverbankcomputing.com Wed Feb 2 03:28:47 2011 From: phil at riverbankcomputing.com (Phil Thompson) Date: Wed, 02 Feb 2011 08:28:47 +0000 Subject: PyQT: QWebView with custom QNetworkAccessManager In-Reply-To: References: Message-ID: <1166e3f11d9bd87fcff29b66e15d7b7f@localhost> On Wed, 02 Feb 2011 02:37:06 +0100, Gelonida wrote: > On 02/02/2011 12:31 AM, Gelonida wrote: >> Hi, >> >> I would like to subclass QNetworkAccessManager and >> create a subclass of QWebView, that will use the subclassed >> QNetworkAccessManager for all accesses. >> >> Is this possible? >> I have really no idea when and how I could achieve this. >> >> Thanks in advance for any suggestions / pointers >> > > > Well I answer my own question. > > In fact my first experiments failed horribly due to a tiny PyQt detail. > > I expected that, the variable new_manager does not have to be persistent. > > I naively assumed, that a call to setNetworkAccessManager() would keep a > reference to new_manager and thus avoid its destruction this does not > seem to be the case. It is the case in current versions. Phil From sandro at e-den.it Wed Feb 2 03:56:05 2011 From: sandro at e-den.it (sandro) Date: Wed, 02 Feb 2011 08:56:05 GMT Subject: How to create an entry in the "Program menu" of Windows? References: <28%1p.9610$gy5.28412@twister1.libero.it> Message-ID: Alexander Kapps wrote: > On 01.02.2011 22:43, Diesel wrote: >> >> Hi, >> >> I'd like to add menu entry in the Program Menu as part of the >> installation of an application. Is it possible to do that from Python? >> >> Any examples or link? I have not been able to find anything with >> google... >> >> thanks in advance >> s/ >> > > AFAIK, the startmenu entries are just .lnk files, placed either in > the "All Users" or "Some Specific User" Startmenu directory. I only > have a German XP and can't boot it to test at the moment, so I can't > give more details, but there are surely registry entries to find the > Startmenu location for the current user or for "All Users". > > See http://codesnippets.joyent.com/posts/show/529 for an example how > to place .lnk files. However, for real deployment, you probably want > to use a real installer framework like NSIS for example. > Thanks Alexander, in the meanwhile I also found this [1] message that reports the following snippet that uses module winshell (and win32...): [1] http://www.mail-archive.com/python-win32 at python.org/msg05411.html import os, sys import winshell startup = winshell.startup () # use common=1 for all users print startup winshell.CreateShortcut ( Path=os.path.join (winshell.startup (), "Python.lnk"), Target=sys.executable, Icon=(sys.executable, 0), Description="Python" ) thanks again *:-) From glicerinu at gmail.com Wed Feb 2 03:56:06 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Wed, 2 Feb 2011 00:56:06 -0800 (PST) Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> Message-ID: On Feb 2, 12:11?am, Peter Otten <__pete... at web.de> wrote: > Marc Aymerich wrote: > > Hi all, > > I want to provide an encapsulated static attribute called _registry > > for several classes. > > > I try to use inheritance in order to make it DRY: all classes inherit > > from a BaseClass that implements the _registry encapsulation. But with > > inheritance it doesn't work how I want, because a single instance of > > the _registry is shared between all of the inherited classes, and I > > want to have an independent _registry for every class. > > > How can I do that without coping all the code in every class? > > If you want to go fancy use a metaclass: > > >>> class Base(object): > > ... ? ? class __metaclass__(type): > ... ? ? ? ? ? ? def __init__(self, *args): > ... ? ? ? ? ? ? ? ? ? ? type.__init__(self, *args) > ... ? ? ? ? ? ? ? ? ? ? self.per_class = [] Many thanks Peter!! From steve+comp.lang.python at pearwood.info Wed Feb 2 04:43:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Feb 2011 09:43:11 GMT Subject: How to create an entry in the "Program menu" of Windows? References: <28%1p.9610$gy5.28412@twister1.libero.it> Message-ID: <4d49272e$0$30000$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Feb 2011 21:43:26 +0000, Diesel wrote: > Hi, > > I'd like to add menu entry in the Program Menu as part of the > installation of an application. Is it possible to do that from Python? Of course. Python is Turing complete, if any language can do it, Python can too (although not necessarily as fast or easily). What operating system and desktop environment are you using? For example, under KDE 3.x, you would choose which Program menu you want to use (Utilities, Office, Internet, Multimedia, etc.), decide whether you want this to apply to all users or just a single user, and then create the appropriate .desktop files. In my not-so humble opinion, it's a mess, but for what it's worth there's a description of it here: http://humanreadable.nfshost.com/howtos/kde-menus.htm -- Steven From steve+comp.lang.python at pearwood.info Wed Feb 2 04:44:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Feb 2011 09:44:17 GMT Subject: test: please ignore References: Message-ID: <4d492770$0$30000$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Feb 2011 22:44:20 +0100, Gelonida wrote: > Somehow I can't post anymore to gmane. > > Would like to know why. I have the answer, but since you've told me to ignore this post, I can't tell you. -- Steven From wander.lairson at gmail.com Wed Feb 2 04:52:02 2011 From: wander.lairson at gmail.com (wander.lairson) Date: Wed, 2 Feb 2011 07:52:02 -0200 Subject: Perl Hacker, Python Initiate In-Reply-To: References: Message-ID: 2011/2/2 Gary Chambers : > All, > > Given the following Perl script: > > #!/usr/bin/perl > > %dig = ( > ? ?solaris => "/usr/sbin/dig", > ? ?linux ? => "/usr/bin/dig", > ? ?darwin ?=> "/usr/bin/dig" > ); > > $DIG = $dig{"$^O"}; > $DOMAIN = "example.com"; > $DNS = "ns.example.com"; > $DIGCMD = qq/$DIG \@$DNS $DOMAIN axfr/; > > open DIG, "$DIGCMD|" or die "$DIG: $!\n"; > while () { > ? ?next if (/^;/); # Skip any comments > ? ?# If we match a CNAME record, we have an alias to something. > ? ?# $1 = alias (CNAME), $2 = canonical hostname > ? ?if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.${DOMAIN}\.$/) { > ? ? ? ?# Push an alias (CNAME) onto an array indexed on canonical hostname > ? ? ? ?push(@{$cnames{$2}}, $1); > ? ?} > ? ?# Here's a standard A (canonical hostname) record > ? ?# $1 = canonical hostname, $2 = IPv4 address > ? ?if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*A\s+(\S+)$/) { > ? ? ? ?$ip{$1} = $2; > ? ?} > } > close DIG; > > # Format and display it like niscat hosts: > # canonicalHostname alias1 [alias2 aliasN] ipAddress > for $host (sort keys %ip) { > ? ?print "$host "; > ? ?if (defined(@{$cnames{$host}})) { > ? ? ? ?print join(' ', @{$cnames{$host}}); > ? ? ? ?print " "; > ? ?} > ? ?print "$ip{$host}\n"; > } > exit 0; > > Will someone please provide some insight on how to accomplish that task in > Python? ?I am unable to continually (i.e. it stops after displaying a single > line) loop through the output while testing for the matches on the two > regular expressions. ?Thank you. > > -- Gary Chambers > -- > http://mail.python.org/mailman/listinfo/python-list > As this is a python list, don't expect people understand Perl code (I don't know Perl, for example). But I understand, you call the /usr/bin/dig program and do some text processing on its ouput. Am I right? If so, you might want to give a look at re and subprocess modules. http://docs.python.org/py3k/howto/regex.html http://docs.python.org/py3k/library/re.html http://docs.python.org/py3k/library/subprocess.html -- Best Regards, Wander Lairson Costa LCoN - Laborat?rio de Computa??o Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de P?s-Gradua??o em Engenharia El?trica (PPGEE) Faculdade de Computa??o e Inform?tica (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil From gelonida at gmail.com Wed Feb 2 04:53:54 2011 From: gelonida at gmail.com (Gelonida Gmail) Date: Wed, 02 Feb 2011 10:53:54 +0100 Subject: PyQT: QWebView with custom QNetworkAccessManager In-Reply-To: <1166e3f11d9bd87fcff29b66e15d7b7f@localhost> References: <1166e3f11d9bd87fcff29b66e15d7b7f@localhost> Message-ID: <4D4929B2.1000204@gmail.com> Hi Phil, On 02/02/2011 09:28 AM, Phil Thompson wrote: > On Wed, 02 Feb 2011 02:37:06 +0100, Gelonida wrote > > In fact my first experiments failed horribly due to a tiny PyQt detail. > > I expected that, the variable new_manager does not have to be > persistent. >> I naively assumed, that a call to setNetworkAccessManager() would keep a >> reference to new_manager and thus avoid its destruction this does not >> seem to be the case. > It is the case in current versions. > > Phil Thanks for the confirmation/ Was using PyQt: 4.7.2 263938 >From which release on is it fixed? From steve+comp.lang.python at pearwood.info Wed Feb 2 04:57:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Feb 2011 09:57:30 GMT Subject: Print docstrings to shell References: Message-ID: <4d492a89$0$30000$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Feb 2011 16:11:51 -0800, Gnarlodious wrote: > Can I run a script in bash and print out its docstrings to the bash > shell? I tried this at the end: [...] > However in the interactive shell it prints out the class structure > nicely. What I really want to see is this output in the bash window. Use the Source, Luke :) See what help() does, and modify it appropriately. See the site and pydoc modules for more information. But there's no need to reinvent the wheel. pydoc already does what you want (or at least what I think you want). Just run "pydoc name" from bash. So long as name is a module in the python path (in other words, so long as "import name" will work), then pydoc will see it too. If you want to write the output out to a file, use "pydoc -w name". -- Steven From steve+comp.lang.python at pearwood.info Wed Feb 2 05:06:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Feb 2011 10:06:36 GMT Subject: Perl Hacker, Python Initiate References: Message-ID: <4d492cac$0$30000$c3e8da3$5496439d@news.astraweb.com> On Tue, 01 Feb 2011 23:36:27 -0500, Gary Chambers wrote: > All, > > Given the following Perl script: [snip line noise] > Will someone please provide some insight on how to accomplish that task > in Python? No idea, I can't read Perl, and you shouldn't assume that people will be able to. Can you simplify your problem to the smallest sub-task that you cannot perform? Focus on this part of the problem: > I am unable to continually (i.e. it stops after displaying a > single line) loop through the output while testing for the matches on > the two regular expressions. Thank you. What Python code are you using to loop? Simplify the problem to focus on the fundamental problem, not the irrelevant details of looking up CNAME and A Records using dig. -- Steven From alain at dpt-info.u-strasbg.fr Wed Feb 2 05:24:13 2011 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 02 Feb 2011 11:24:13 +0100 Subject: Perl Hacker, Python Initiate References: Message-ID: <871v3qpwdu.fsf@dpt-info.u-strasbg.fr> Gary Chambers writes: > Given the following Perl script: [41 lines of Perl removed] Sorry, I'm lucky enough to be able to completely ignore Perl. > Will someone please provide some insight on how to accomplish that task in > Python? >From what I understood in the comments of your script, here is a possible python scriptlet: import sys import socket canon,aliases,ipaddrs = socket.gethostbyname_ex(sys.argv[1]) print canon,",".join(aliases),",".join(ipaddrs) See also getaddrinfo(). Note that a canonical name may have several ip addresses (try with www.google.com if you doubt). (BTW, this is a direct interface to gethostbyname(), and there is no real need to use a tool and parse its output.) > I am unable to continually (i.e. it stops after displaying a single > line) loop through the output while testing for the matches on the two > regular expressions. Thank you. It is hard to guess what you've tried. See the subprocess package documentation. -- Alain. From __peter__ at web.de Wed Feb 2 06:18:44 2011 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 Feb 2011 12:18:44 +0100 Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> Message-ID: Marc Aymerich wrote: > On Feb 2, 12:11 am, Peter Otten <__pete... at web.de> wrote: >> Marc Aymerich wrote: >> > Hi all, >> > I want to provide an encapsulated static attribute called _registry >> > for several classes. >> >> > I try to use inheritance in order to make it DRY: all classes inherit >> > from a BaseClass that implements the _registry encapsulation. But with >> > inheritance it doesn't work how I want, because a single instance of >> > the _registry is shared between all of the inherited classes, and I >> > want to have an independent _registry for every class. >> >> > How can I do that without coping all the code in every class? >> >> If you want to go fancy use a metaclass: >> >> >>> class Base(object): >> >> ... class __metaclass__(type): >> ... def __init__(self, *args): >> ... type.__init__(self, *args) >> ... self.per_class = [] > > > Many thanks Peter!! Here's a variant that doesn't rely on the metaclass: class Base(object): registries = {} @property def per_class(self): cls = type(self) try: return self.registries[cls] except KeyError: result = self.registries[cls] = [] return result class A(Base): pass class B(Base): pass assert A().per_class is A().per_class assert B().per_class is B().per_class assert A().per_class is not B().per_class From tom at t0mb.net Wed Feb 2 06:44:30 2011 From: tom at t0mb.net (Tom Boland) Date: Wed, 02 Feb 2011 11:44:30 +0000 Subject: Perl Hacker, Python Initiate In-Reply-To: <871v3qpwdu.fsf@dpt-info.u-strasbg.fr> References: <871v3qpwdu.fsf@dpt-info.u-strasbg.fr> Message-ID: <4D49439E.6070600@t0mb.net> if you want to do dns lookups on a large number of hosts, then try looking at gnu adns, or if you don't mind each request blocking until it's complete, then see Alain's response below. I have written some scripts myself which do massively parallel dns lookups quickly using twisted. If this is an excercise in just trying to do a straight port of your program, and you're not interested in doing it in a nicer fashion, then I would see the simple response from Carl Banks, however, you should really have posted the python code you're trying instead! Cheers. Tom. On 02/02/11 10:24, Alain Ketterlin wrote: > Gary Chambers writes: > > >> Given the following Perl script: >> > [41 lines of Perl removed] > > Sorry, I'm lucky enough to be able to completely ignore Perl. > > >> Will someone please provide some insight on how to accomplish that task in >> Python? >> > > From what I understood in the comments of your script, here is a possible > python scriptlet: > > import sys > import socket > canon,aliases,ipaddrs = socket.gethostbyname_ex(sys.argv[1]) > print canon,",".join(aliases),",".join(ipaddrs) > > See also getaddrinfo(). Note that a canonical name may have several ip > addresses (try with www.google.com if you doubt). > > (BTW, this is a direct interface to gethostbyname(), and there is no > real need to use a tool and parse its output.) > > >> I am unable to continually (i.e. it stops after displaying a single >> line) loop through the output while testing for the matches on the two >> regular expressions. Thank you. >> > It is hard to guess what you've tried. See the subprocess package > documentation. > > -- Alain. > From glicerinu at gmail.com Wed Feb 2 06:53:57 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Wed, 2 Feb 2011 03:53:57 -0800 (PST) Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> Message-ID: <337dd9ef-4b1f-49f1-b40c-67df7cdbec81@33g2000pru.googlegroups.com> On Feb 2, 12:11?am, Peter Otten <__pete... at web.de> wrote: > Marc Aymerich wrote: > > Hi all, > > I want to provide an encapsulated static attribute called _registry > > for several classes. > > > I try to use inheritance in order to make it DRY: all classes inherit > > from a BaseClass that implements the _registry encapsulation. But with > > inheritance it doesn't work how I want, because a single instance of > > the _registry is shared between all of the inherited classes, and I > > want to have an independent _registry for every class. > > > How can I do that without coping all the code in every class? > > If you want to go fancy use a metaclass: > > >>> class Base(object): > > ... ? ? class __metaclass__(type): > ... ? ? ? ? ? ? def __init__(self, *args): > ... ? ? ? ? ? ? ? ? ? ? type.__init__(self, *args) > ... ? ? ? ? ? ? ? ? ? ? self.per_class = [] > ...>>> class A(Base): pass > ... > >>> A().per_class is A().per_class > True > >>> class B(Base): pass > ... > >>> B().per_class is B().per_class > True > >>> A().per_class is B().per_class > > False Hi!, Unfortunately per_class attribute losses the "independence" when I try to mix it with django models.Model . from django.db import models class Plugin(models.base.ModelBase): class __metaclass__(type): def __init__(self, *args): type.__init__(self, *args) self.per_class = [] class BaseService(models.Model): class Meta: abstract = True __metaclass__ = Plugin class VirtualHost(BaseService): name = models.CharField(max_length=10) class SystemUser(BaseService): name = models.CharField(max_length=10) >>> VirtualHost.per_class is SystemUser.per_class True What am I doing wrong? Thanks again! From glicerinu at gmail.com Wed Feb 2 07:12:58 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Wed, 2 Feb 2011 04:12:58 -0800 (PST) Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> Message-ID: On Feb 2, 12:18?pm, Peter Otten <__pete... at web.de> wrote: > Marc Aymerich wrote: > > On Feb 2, 12:11 am, Peter Otten <__pete... at web.de> wrote: > >> Marc Aymerich wrote: > >> > Hi all, > >> > I want to provide an encapsulated static attribute called _registry > >> > for several classes. > > >> > I try to use inheritance in order to make it DRY: all classes inherit > >> > from a BaseClass that implements the _registry encapsulation. But with > >> > inheritance it doesn't work how I want, because a single instance of > >> > the _registry is shared between all of the inherited classes, and I > >> > want to have an independent _registry for every class. > > >> > How can I do that without coping all the code in every class? > > >> If you want to go fancy use a metaclass: > > >> >>> class Base(object): > > >> ... ? ? class __metaclass__(type): > >> ... ? ? ? ? ? ? def __init__(self, *args): > >> ... ? ? ? ? ? ? ? ? ? ? type.__init__(self, *args) > >> ... ? ? ? ? ? ? ? ? ? ? self.per_class = [] > > > Many thanks Peter!! > > Here's a variant that doesn't rely on the metaclass: > > class Base(object): > ? ? registries = {} > ? ? @property > ? ? def per_class(self): > ? ? ? ? cls = type(self) > ? ? ? ? try: > ? ? ? ? ? ? return self.registries[cls] > ? ? ? ? except KeyError: > ? ? ? ? ? ? result = self.registries[cls] = [] > ? ? ? ? ? ? return result > > class A(Base): pass > class B(Base): pass > > assert A().per_class is A().per_class > assert B().per_class is B().per_class > assert A().per_class is not B().per_class Wow, many many thanks Peter, this works perfectly for me :) From antonyjeevaraj at gmail.com Wed Feb 2 07:22:41 2011 From: antonyjeevaraj at gmail.com (antony jeevaraj) Date: Wed, 2 Feb 2011 04:22:41 -0800 (PST) Subject: REFER YOUR FRIENDS & EARN RS 20,000 TODAY (NO INVESTMENT) Message-ID: REFER YOUR FRIENDS & EARN RS 20,000 TODAY (NO INVESTMENT) AEESY affiliate program is for web marketers who want to start generating huge commissions, from the selling of online marketing, and other high converting products. Join the affiliate program & make money free : Get $1 per referral + 10% Referral earnings (NO INVESTMENT) If you Refer 100 friends to this network EARN $100 TODAY (RS 5000) If you Refer 500 friends to this network EARN $500 TODAY (RS 20,000) Weekly payment, Get paid through paypal,wire transfer Enter Your Payment Details ,Join This Network ,Get your Promotional Link,Start Earn $$$$$$$ http://aeesy.com/signup.php?aff=qt1umw From joncle at googlemail.com Wed Feb 2 07:52:53 2011 From: joncle at googlemail.com (Jon Clements) Date: Wed, 2 Feb 2011 04:52:53 -0800 (PST) Subject: Converting getCSS Count Code from java to python References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> Message-ID: <4e3639fd-3584-4462-95b2-7e1ef44b5298@t19g2000prd.googlegroups.com> On Feb 1, 4:23?am, SMERSH009 wrote: > Hi, I'd love some help converting this code to the python equivalent: > > private int getCSSCount(String aCSSLocator){ > ? ? String jsScript = "var cssMatches = eval_css(\"%s\", > window.document);cssMatches.length;"; > ? ? return Integer.parseInt(selenium.getEval(String.format(jsScript, > aCSSLocator))); > > } > > http://www.eviltester.com/index.php/2010/03/13/a-simple-getcsscount-h... > > Thanks for the help Maybe? http://codespeak.net/lxml/dev/cssselect.html Jon. From subscriptions at cagttraining.com Wed Feb 2 08:05:22 2011 From: subscriptions at cagttraining.com (Bill Felton) Date: Wed, 2 Feb 2011 08:05:22 -0500 Subject: [Announce] Python Lansing (MI) User Group first meeting Feb. 24 2011 Message-ID: <5F30F2F1-E062-402F-9D32-5B0C19F454D9@cagttraining.com> This is to announce the first meeting of the newly formed Python Lansing User Group in Lansing Michigan. The group has been organized on Meetup.com. The meeting will be held at Second Gear Coworking, 1134 N. Washington Lansing, MI at 6PM. Please join us on meetup and at the kick-off meeting. Looking forward to seeing you there! cheers, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Feb 2 08:14:15 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 02 Feb 2011 14:14:15 +0100 Subject: Converting getCSS Count Code from java to python In-Reply-To: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> Message-ID: SMERSH009, 01.02.2011 05:23: > Hi, I'd love some help converting this code to the python equivalent: > > private int getCSSCount(String aCSSLocator){ > String jsScript = "var cssMatches = eval_css(\"%s\", > window.document);cssMatches.length;"; > return Integer.parseInt(selenium.getEval(String.format(jsScript, > aCSSLocator))); > } > > http://www.eviltester.com/index.php/2010/03/13/a-simple-getcsscount-helper-method-for-use-with-selenium-rc/ You are using Selenium RC here. I have no idea if there is a Python API to it or what that API looks like. The rest is just trivial code that you can map 1:1 to Python: def count_css_matches(css_locator): java_script_code = ''' var cssMatches = eval_css("%s", window.document); cssMatches.length;''' % css_locator return int(selenium.getEval(java_script_code)) Although I'd simplify the JavaScript code somewhat to make it a plain expression. If that's not what you want, please be more precise, or look at the CSS selectors in lxml that Jon Clemens pointed you to. Stefan From duncan.booth at invalid.invalid Wed Feb 2 10:03:31 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 Feb 2011 15:03:31 GMT Subject: Converting getCSS Count Code from java to python References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> Message-ID: Stefan Behnel wrote: > You are using Selenium RC here. I have no idea if there is a Python > API to it or what that API looks like. The rest is just trivial code > that you can map 1:1 to Python: > > def count_css_matches(css_locator): > java_script_code = ''' > var cssMatches = eval_css("%s", window.document); > cssMatches.length;''' % css_locator > return int(selenium.getEval(java_script_code)) > > Although I'd simplify the JavaScript code somewhat to make it a plain > expression. You also need somewhere: from selenium import selenium and in Python the method that is needed is selenium.get_eval(...) -- Duncan Booth http://kupuguy.blogspot.com From gwchamb at gwcmail.com Wed Feb 2 11:00:11 2011 From: gwchamb at gwcmail.com (Gary Chambers) Date: Wed, 2 Feb 2011 11:00:11 -0500 (EST) Subject: Perl Hacker, Python Initiate In-Reply-To: <87sjw7vxt6.fsf@benfinney.id.au> References: <87sjw7vxt6.fsf@benfinney.id.au> Message-ID: All, > Insight will be easier to provide once we see your Python code. Thanks to all of you who replied to my original request for assistance. All points are valid and well-taken. I'm afraid that I can no longer locate the original Python code where I was encountering the problem I described in my request. Unfortunately, I chose to teach myself Python by first porting that script directly (for better or worse, just trying to make it work). Time constraints, a bit of frustration, and simply being comfortable and efficient in Perl have relegated the task to a far back burner. Since then, I've forwarded the Perl code to a few others to see if they could provide a solution, but have heard nothing in reply -- which is why I presented it to a world of real Python experts. If you can't make heads or tails of the Perl code, all I'm trying to do is loop through some dig output of a DNS zone transfer. There are two conditions I need to test: whether it's an A or CNAME record. Ultimately, I need to assemble the data into a single line listing first the canonical hostname (A), followed by the aliases (CNAME), and finally the IP address. For example: were-on-vacation wov vacation vaca holiday 192.168.110.121 Finally, the problem I encountered in the Python code was having the script fail when it encountered a line that didn't match either of the two regular expressions. What I'm seeking is either some Python code that mimics what my Perl script is doing, or to be shown the Python way of how to accomplish something like that. Surprisingly, there's no mention of regular expressions in the Perl Phrasebook at http://wiki.python.org/moin/PerlPhrasebook. -- Gary Chambers From michele.simionato at gmail.com Wed Feb 2 11:58:45 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 2 Feb 2011 08:58:45 -0800 (PST) Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> <337dd9ef-4b1f-49f1-b40c-67df7cdbec81@33g2000pru.googlegroups.com> Message-ID: Notice that Peter's approach also works without inheritance: registries = {} @property def per_class(self): cls = type(self) try: return registries[cls] except KeyError: result = registries[cls] = [] return result class A(object): per_class=per_class class B(object): per_class=per_class assert A().per_class is A().per_class assert B().per_class is B().per_class assert A().per_class is not B().per_class (you can also put the per_class property in a module and import it with class A(object): from module import per_class). There is no need to use inheritance if you only need one method. Notice also that if you are working with a complex third party framework (say Django) that may use metaclasses or strange tricks (such as __slots__) the safer way is to avoid both inheritance and metaclasses. HTH, Michele From develsoftware at gmail.com Wed Feb 2 12:21:40 2011 From: develsoftware at gmail.com (=?UTF-8?B?0JXQstCz0LXQvdC40Lkg0J/QvtGH0LjRgtCw0LXQsg==?=) Date: Wed, 2 Feb 2011 09:21:40 -0800 (PST) Subject: Python/C API Inheritance Message-ID: Hi to all. May be someone do class inheritance in Python/C API, I know how create superclass/subclass. But how I can initialize superclass from subclass initializer? struct SuperClass { PyObject_HEAD; //... }; struct SubClass { PyObject_HEAD; //... }; static int SubClassInit(SubClass *self, PyObject *args, PyObject *kwds) { // how I should initialize super class? } PyTypeObject SuperClassType = { //... }; PyTypeObject SubClassType = { PyObject_HEAD_INIT(NULL) 0, /* ob_size*/ //... SubClassInit, /* tp_init */ //... NULL, /* tp_getset */ &SuperClassType, /* tp_base */ NULL, /* tp_dict */ //... }; Another question how I can access to superclass from subclass(I need get access to SuperClass C struct members)? Thanks. From stefan_ml at behnel.de Wed Feb 2 12:55:37 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 02 Feb 2011 18:55:37 +0100 Subject: Python/C API Inheritance In-Reply-To: References: Message-ID: ??????? ????????, 02.02.2011 18:21: > May be someone do class inheritance in Python/C API, I know how create > superclass/subclass. But how I can initialize superclass from subclass > initializer? > > struct SuperClass { > PyObject_HEAD; > //... > }; > > struct SubClass { > PyObject_HEAD; You need to insert the super class struct here, not a plain new object struct. In case you want to avoid stumbling over problems like this and instead concentrate on getting functionality implemented, take a look at Cython. http://cython.org Stefan From redjohn367 at gmail.com Wed Feb 2 13:12:38 2011 From: redjohn367 at gmail.com (Red John) Date: Wed, 2 Feb 2011 10:12:38 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On Feb 1, 11:23?am, rantingrick wrote: > Hmm, that coming from someone who has two posts in this group. And the > last he posted was a year ago! Alright, let me add you to the proper > category... > > py> troll_group.append("Red John") I realize that not agreeing with you is enough to be labeled a troll - which is fine with me, a lot of my favorite posters were in that group :) - but I fail to see how it's relevant that I prefer reading others' ideas. From phil at riverbankcomputing.com Wed Feb 2 13:32:09 2011 From: phil at riverbankcomputing.com (Phil Thompson) Date: Wed, 02 Feb 2011 18:32:09 +0000 Subject: PyQT: QWebView with custom QNetworkAccessManager In-Reply-To: <4D4929B2.1000204@gmail.com> References: <1166e3f11d9bd87fcff29b66e15d7b7f@localhost> <4D4929B2.1000204@gmail.com> Message-ID: <3c9026d16833fe8699d1e24c434f7b07@localhost> On Wed, 02 Feb 2011 10:53:54 +0100, Gelonida Gmail wrote: > Hi Phil, > > On 02/02/2011 09:28 AM, Phil Thompson wrote: >> On Wed, 02 Feb 2011 02:37:06 +0100, Gelonida wrote >> >> In fact my first experiments failed horribly due to a tiny PyQt detail. >> >> I expected that, the variable new_manager does not have to be >> persistent. >>> I naively assumed, that a call to setNetworkAccessManager() would keep a >>> reference to new_manager and thus avoid its destruction this does not >>> seem to be the case. >> It is the case in current versions. >> >> Phil > > Thanks for the confirmation/ > > > Was using PyQt: 4.7.2 263938 > > From which release on is it fixed? v4.8 Phil From yelena.mqw at gmail.com Wed Feb 2 14:19:00 2011 From: yelena.mqw at gmail.com (Yelena) Date: Wed, 2 Feb 2011 11:19:00 -0800 (PST) Subject: python crash problem Message-ID: <701afd55-9ba3-4dc8-91c9-e6d5065266c5@x11g2000yqc.googlegroups.com> I've been using python to run some large database recently. I used dbfpy module to access some information stored in dbf format. However, after 20hrs of running it gave me an error of : Runtime Error! This application has requested the Runtime to terminate it in an unusual way.Please contact the application's support team for more information. The error popped out every time I ran them after 20 hrs. My prediction was that it ran over its memory usage, since it has been accumulating the memory usage when I was running the program. So I tried deleting/closing I/O immediately after they were processed. However, such changes did not make any difference in memory usage accumulation. Could you please give me some advice in fixing problems like this? Thank you From yelena.mqw at gmail.com Wed Feb 2 14:21:15 2011 From: yelena.mqw at gmail.com (Yelena) Date: Wed, 2 Feb 2011 11:21:15 -0800 (PST) Subject: python crash problem References: <701afd55-9ba3-4dc8-91c9-e6d5065266c5@x11g2000yqc.googlegroups.com> Message-ID: <71e19715-3bd3-4422-9a6a-6e88a778bed0@e21g2000yqe.googlegroups.com> Here is the code, I edited out some private info: import sys import urllib2 import string import re import datetime from mx import DateTime from dbfpy import dbf addylist = ['add.dbf'] okset = ['P','L','I','B'] for addy in addylist: db = dbf.Dbf(addy) print (addy) count = len(db) db.close() del db foo = ((0, 1000),(1000,count/3), (count/3, count/3*2), (count/3*2, count)) for (start,finish) in foo: ab = dbf.Dbf(addy) for x in range(start, finish): print x rec = ab[x] if rec["flag"] in [1,3]: INP_info = rec["address"] + " " + rec["city"] + " " +rec["state"] + " " + rec["zip"] INP_info = INP_info.replace(' ',',') HOST_URL = '***' KEY = '***' STD_URL = '***' STD_URL = STD_URL.replace('location=','location=' + INP_info) STD_URL = STD_URL.replace('key=','key=' + KEY) Addy_INPUT = HOST_URL + STD_URL try: for line in urllib2.urlopen(Addy_INPUT): safe = line geoQ = safe.find('\"geocodeQualityCode\"',1) geoCode = safe[(geoQ+22):(geoQ+26)] if geoCode[0] in okset: lat = safe.find('\"lat\":', 1) lng = safe.find('\"lng\":', 1) lngbound = safe.find('\"mapUrl":', 1) zipCode = safe.find('\"postalCode\"', 1) zipbound = safe.find('\"adminArea1\"', 1) rec["lat"] = float(safe[(lat + 6): (lng-1)]) rec["long"] = float(safe[(lng+6): (lngbound-2)]) rec["zip_final"] = safe[(zipCode+14): (zipbound-2)] rec["flag"] = 2 print ('ok ') else: rec["flag"] = 5 except: rec["flag"] = 5 rec.store() del rec ab.close() del ab From rantingrick at gmail.com Wed Feb 2 14:44:19 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 2 Feb 2011 11:44:19 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On Feb 2, 12:12?pm, Red John wrote: > On Feb 1, 11:23?am, rantingrick wrote: > > > Hmm, that coming from someone who has two posts in this group. And the > > last he posted was a year ago! Alright, let me add you to the proper > > category... > > > py> troll_group.append("Red John") > > I realize that not agreeing with you is enough to be labeled a troll - > which is fine with me, a lot of my favorite posters were in that > group :) - but I fail to see how it's relevant that I prefer reading > others' ideas. Here let me show you why you find yourself in the company of trolls... Red John said: > Go away. You are easily one of the worst (and definitely most > annoying) person I've encountered in person or online, which is > saying something because I used to frequent 4chan. That is all you have brought to this conversion so far. You have not offered solutions for IDLE, heck you don't even inject an opinion of IDLE. You just spew bile. Have fun with your new playmates. py> flamer_group.append(troll_group.pop("Corey Richardson")) Your moving up Corey. Keep up the good work! From glicerinu at gmail.com Wed Feb 2 15:32:44 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Wed, 2 Feb 2011 12:32:44 -0800 (PST) Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> <337dd9ef-4b1f-49f1-b40c-67df7cdbec81@33g2000pru.googlegroups.com> Message-ID: On Feb 2, 5:58?pm, Michele Simionato wrote: > Notice that Peter's approach also works without inheritance: > > registries = {} > > @property > def per_class(self): > ? ?cls = type(self) > ? ?try: > ? ? ? return registries[cls] > ? ?except KeyError: > ? ? ? result = registries[cls] = [] > ? ? ? return result > > class A(object): per_class=per_class > class B(object): per_class=per_class > assert A().per_class is A().per_class > assert B().per_class is B().per_class > assert A().per_class is not B().per_class > > (you can also put the per_class property in a module and import it > with > class A(object): from module import per_class). > > There is no need to use inheritance if you only need one method. > Notice also that if you > are working with a complex third party framework (say Django) that may > use metaclasses > or strange tricks (such as __slots__) the safer way is to avoid both > inheritance and metaclasses. > HTH, > > ?Michele Hi Michele, thanks for your contributions. Actually the Petter proposal it's working for me (AFAIK). I think because my base class is an abstract class. In particular my adaptation of his proposal (with the rest of the current BaseService class) is: from django.db import models from django.contrib.contenttypes import generic class BaseService(models.Model): class Meta: abstract = True _service_registry = [] _plugin_registry = {} @classmethod def plugin_register(cls, str): # Per subclass register try: cls._plugin_registry[cls].append(str) except KeyError: cls._plugin_registry[cls] = [] @classmethod def get_plugin_registred(cls): # Per subclass register try: return cls._plugin_registry[cls] except KeyError: result = cls._plugin_registry[cls] = [] return result @property def extentions_attributes(self): attributes = [] for model in _plugin_registry: for attribute in model.get_attributes(self): attributes.append(attribute[0]) return attributes @classmethod def service_register(cls): cls._service_registry.append(cls) @classmethod def get_service_registred(cls): return cls._service_registry @property def attributes(self): return [] IMHO Django handles very well inheritance, and subclassing is their major method in order to use the framework. I completely agree with metaclasses should be avoided when you're working with frameworks :) BTW, is there any alternative to the inheritance pattern in order to provide this set of methods for multiple classes? I'm pretty new in OOP :) Thanks! From kb1pkl at aim.com Wed Feb 2 15:41:47 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Wed, 02 Feb 2011 15:41:47 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: <4D49C18B.5080307@aim.com> On 2/2/2011 2:44 PM, rantingrick wrote: > [snip] > py> flamer_group.append(troll_group.pop("Corey Richardson")) > > Your moving up Corey. Keep up the good work! I don't recall ever doing anything but injecting my honest opinion. If my opinion may be flawed (or appears to be flawed, I usually don't elaborate on my ideas enough), so be it. Will you be forking IDLE and setting up some sort of tracker for improvements? From r at thevoid1.net Wed Feb 2 16:08:30 2011 From: r at thevoid1.net (Robin) Date: Wed, 2 Feb 2011 13:08:30 -0800 (PST) Subject: python question Message-ID: how do you acccess a hash element in python 3? It completely changed from version 2 and earlier, I think. stop war straight up, direct or indectly, From enalicho at gmail.com Wed Feb 2 16:09:39 2011 From: enalicho at gmail.com (Noah Hall) Date: Wed, 2 Feb 2011 21:09:39 +0000 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On Wed, Feb 2, 2011 at 7:44 PM, rantingrick wrote: >> On Feb 1, 11:23?am, rantingrick wrote: >> > py> troll_group.append("Red John") > py> flamer_group.append(troll_group.pop("Corey Richardson")) Out of interest, what interpretor uses "py>"? I've never seen any. Just sayin'. From tjreedy at udel.edu Wed Feb 2 16:11:26 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 Feb 2011 16:11:26 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <4D48A94A.3040305@aim.com> References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> <4D48A94A.3040305@aim.com> Message-ID: On 2/1/2011 7:46 PM, Corey Richardson wrote: > On 02/01/2011 07:42 PM, Robert wrote: >> On 2011-02-01 10:54:26 -0500, Terry Reedy said: >>> Perhaps, after the repository moves from svn to hg, some 'we' will. >> If he does not, I think I might. Is there a timeline for the move? Unclear. Many want immediately, > I would help with such a project as well, given the opportunity. You both might sign up to idle-sig list. Or 'subscribe' to gmane.comp.python.idle newsgroup mirror. Current traffic is 0. And thank you both for chiming in. It is encouraging. -- Terry Jan Reedy From benjamin.kaplan at case.edu Wed Feb 2 16:19:01 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 2 Feb 2011 16:19:01 -0500 Subject: python question In-Reply-To: References: Message-ID: On Wed, Feb 2, 2011 at 4:08 PM, Robin wrote: > > how do you acccess a hash element in python 3? It completely changed > from version 2 and earlier, I think. > What do you mean by accessing a hash element? Do you mean the hash of an object? Because that's stayed the same: hash(obj). Do you mean accessing the values in a dict? Because that's also stayed the same: dictionary[obj]. Or is it something else that you're looking for? > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Wed Feb 2 16:21:49 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 Feb 2011 16:21:49 -0500 Subject: python crash problem In-Reply-To: <701afd55-9ba3-4dc8-91c9-e6d5065266c5@x11g2000yqc.googlegroups.com> References: <701afd55-9ba3-4dc8-91c9-e6d5065266c5@x11g2000yqc.googlegroups.com> Message-ID: On 2/2/2011 2:19 PM, Yelena wrote: > I've been using python Which version? > to run some large database recently. > I used dbfpy module to access some information stored in dbf format. When having a problem with a 3rd party module, not part of the stdlib, you should give a source. http://sourceforge.net/projects/dbfpy/ This appears to be a compiled extension. Nearly always, when Python crashes running such, it is a problem with the extension. So you probably need to direct your question to the author or a project mailing list if there is one. -- Terry Jan Reedy From tjreedy at udel.edu Wed Feb 2 16:24:43 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 Feb 2011 16:24:43 -0500 Subject: wxPython's "Print" Help In-Reply-To: <8ad59b6e-8f69-4a90-8de2-9b3ac2e1438a@n18g2000vbq.googlegroups.com> References: <8ad59b6e-8f69-4a90-8de2-9b3ac2e1438a@n18g2000vbq.googlegroups.com> Message-ID: On 2/2/2011 12:36 AM, Akand Islam wrote: wxPython has its own mailing list. If you prefer newsgroups, like I do, connect to news.gmane.org and subscribe to comp.lang.python.wxpython. -- Terry Jan Reedy From emile at fenx.com Wed Feb 2 16:25:29 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 02 Feb 2011 13:25:29 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On 2/2/2011 1:09 PM Noah Hall said... > On Wed, Feb 2, 2011 at 7:44 PM, rantingrick wrote: >>> On Feb 1, 11:23 am, rantingrick wrote: >>>> py> troll_group.append("Red John") >> py> flamer_group.append(troll_group.pop("Corey Richardson")) > > > Out of interest, what interpretor uses "py>"? > I've never seen any. Just sayin'. ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.ps1 '>>> ' >>> sys.ps1="py>" py> From emile at fenx.com Wed Feb 2 16:40:53 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 02 Feb 2011 13:40:53 -0800 Subject: python crash problem In-Reply-To: <701afd55-9ba3-4dc8-91c9-e6d5065266c5@x11g2000yqc.googlegroups.com> References: <701afd55-9ba3-4dc8-91c9-e6d5065266c5@x11g2000yqc.googlegroups.com> Message-ID: On 2/2/2011 11:19 AM Yelena said... > This application has requested the Runtime to terminate it in an > unusual way This is a MS message -- did you look in the application event viewer? Otherwise, you could try upping/reducing memory and confirm it dies later/earlier. Perhaps there's an at or scheduled job killing off python processes? How big is count? Does this job run for 20 hours straight? Or is it launched periodically? Why the foo fudging? Just to break the process into pieces? You could have the job log it's record number after N hours (where N<20) and simply restart it... Emile From enalicho at gmail.com Wed Feb 2 16:43:53 2011 From: enalicho at gmail.com (Noah Hall) Date: Wed, 2 Feb 2011 21:43:53 +0000 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On Wed, Feb 2, 2011 at 9:25 PM, Emile van Sebille wrote: > ActivePython 2.6.1.1 (ActiveState Software Inc.) based on > Python 2.6.1 (r261:67515, Dec ?5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] > on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> sys.ps1 > '>>> ' >>>> sys.ps1="py>" > py> I know how to do it already, thanks, but I've never seen it native. ;) From rantingrick at gmail.com Wed Feb 2 16:45:01 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 2 Feb 2011 13:45:01 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: <610273b5-b2b8-4028-ab32-e4efb83a225f@w19g2000yqa.googlegroups.com> On Feb 2, 2:41?pm, Corey Richardson wrote: > I don't recall ever doing anything but injecting my honest opinion. If > my opinion may be flawed (or appears to be flawed, I usually don't > elaborate on my ideas enough), so be it. Yes you are correct. When i added you to the troll list that was by accident. You are obviously not a troll and probably not a flamer either. Anyone willing to offer help is a moderate so there you go... py> moderate_group.append(flamer_group.pop("Corey Richardson")) > Will you be forking IDLE and setting up some sort of tracker for > improvements? No because we already have a bug tracker set up for IDLE. Why create another one? We just need the "powers that be" to start accepting major changes to the IDLE library at hand. There is not even enough interest to get minor changes committed. A fork would be the best idea however i am not going to start it alone. If someone else wants to start a fork be my guest, i will be happy to help out once the fork is established. However i am always very reluctant to start these things because the powers that be have not even expressed even the *smallest* interest in change. Sure Raymond, and Terry are interested but how about the others? We have yet to hear from the other BIG players. All we have gotten so far is trolling, threating, and negativity from a few very loud naysayers. Now, after all this uphill battle i have fought only two brave souls (Corey and Richard) have showed an interest in actually doing something. And believe me i thank them! These are great people! But were is the blessing from on high? Where is Steve Holden on this? Is he too busy with $295.00 per session O-Reilly classes to stop by and give his blessing. Were is py-dev on this? I know these folks have *real* work to do however a quick "we're with you guys!", or a simple "break a leg!" would be very helpful. And last but not least, were oh were has our BDFL gone? For years he has hidden his face from us at c.l.py. We have walked in the shadows for far too long Guido. Were is YOUR opinion on these things. When will you weigh in on these very important issues? When! Are we not worthy of a simple: "Yes, improving IDLE's code base sounds good to me." or a simple: "Sorry, i don't think we should worry about that because X,Y,Z." Come on Guido we need your input already! If some big players would show even the smallest support for improving IDLE (or any module) then that positivity would propagate down to the rest of us. The naysayers would stop trolling and the silent majority would start getting involved. From sigzero at gmail.com Wed Feb 2 16:46:00 2011 From: sigzero at gmail.com (Robert) Date: Wed, 2 Feb 2011 16:46:00 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <4871f$4d4734d6$4275d90a$28417@FUSE.NET> <4D48A94A.3040305@aim.com> Message-ID: On 2011-02-02 16:11:26 -0500, Terry Reedy said: > On 2/1/2011 7:46 PM, Corey Richardson wrote: >> On 02/01/2011 07:42 PM, Robert wrote: >>> On 2011-02-01 10:54:26 -0500, Terry Reedy said: > >>>> Perhaps, after the repository moves from svn to hg, some 'we' will. > >>> If he does not, I think I might. Is there a timeline for the move? > > Unclear. Many want immediately, > >> I would help with such a project as well, given the opportunity. > > You both might sign up to idle-sig list. Or 'subscribe' to > gmane.comp.python.idle newsgroup mirror. Current traffic is 0. > > And thank you both for chiming in. It is encouraging. Well, I am about to sign up for the Steve Holden O'Reilly classes to learn Python and I know doing something in Tkinter is part of that. I also have the old Grayson book (just wish Pmw wasn't in there so much). So this would be a good follow on to the class to keep me learning Python at a steady pace. :-) -- Robert From pavlovevidence at gmail.com Wed Feb 2 17:11:28 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 2 Feb 2011 14:11:28 -0800 (PST) Subject: Perl Hacker, Python Initiate References: <87sjw7vxt6.fsf@benfinney.id.au> Message-ID: On Feb 2, 8:00?am, Gary Chambers wrote: > All, > > > Insight will be easier to provide once we see your Python code. > > Thanks to all of you who replied to my original request for assistance. ?All > points are valid and well-taken. > > I'm afraid that I can no longer locate the original Python code where I was > encountering the problem I described in my request. ?Unfortunately, I chose > to teach myself Python by first porting that script directly (for better or > worse, just trying to make it work). ?Time constraints, a bit of > frustration, and simply being comfortable and efficient in Perl have > relegated the task to a far back burner. So use Perl then, if that's what you're familiar with and you don't have time to learn Python. > ?Since then, I've forwarded the > Perl code to a few others to see if they could provide a solution, but have > heard nothing in reply -- which is why I presented it to a world of real > Python experts. How much money did you offer them to translate your script for you? Maybe they were unsatisfied with your offer. > If you can't make heads or tails of the Perl code, all I'm trying to do is > loop through some dig output of a DNS zone transfer. ?There are two > conditions I need to test: whether it's an A or CNAME record. ?Ultimately, I > need to assemble the data into a single line listing first the canonical > hostname (A), followed by the aliases (CNAME), and finally the IP address. I'll do it for US$150. Carl Banks From ben+python at benfinney.id.au Wed Feb 2 17:47:10 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 03 Feb 2011 09:47:10 +1100 Subject: Perl Hacker, Python Initiate References: <87sjw7vxt6.fsf@benfinney.id.au> Message-ID: <87d3navytt.fsf@benfinney.id.au> Gary Chambers writes: > If you can't make heads or tails of the Perl code, all I'm trying to > do is loop through some dig output of a DNS zone transfer. The request to see your Python code was partly because Perl is foreign here, yes. But another, more significant reason is: we want to see *your* attempt at the solution in Python. That will be much more instructive to us of what it is we need to be talking about. Please make a small example Python program, that is complete but is not behaving as you want, and present it here along with a description of what is wrong from your perspective. -- \ ?It seems intuitively obvious to me, which means that it might | `\ be wrong.? ?Chris Torek | _o__) | Ben Finney From invalid at invalid.invalid Wed Feb 2 17:51:30 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 2 Feb 2011 22:51:30 +0000 (UTC) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: On 2011-01-31, rantingrick wrote: > IDLE: A cornicopia of mediocrity and obfuscation. > -- by Rick Johnson RR's postings are generally tossed out by my score file, but after seeing so many replies, my morbid curiousity finally got the best of me, and I read (well, mostly) RR's posting on what's wrong with IDLE. > -- rr: disappointed and annoyed! Shocker. We'll take it as read that I made some joke at this point involving one of the definitions of "idle" as meaning running your motor and not going anywhere... -- Grant Edwards grant.b.edwards Yow! My uncle Murray at conquered Egypt in 53 B.C. gmail.com And I can prove it too!! From jason.swails at gmail.com Wed Feb 2 17:55:12 2011 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 2 Feb 2011 17:55:12 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <610273b5-b2b8-4028-ab32-e4efb83a225f@w19g2000yqa.googlegroups.com> References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <610273b5-b2b8-4028-ab32-e4efb83a225f@w19g2000yqa.googlegroups.com> Message-ID: On Wed, Feb 2, 2011 at 4:45 PM, rantingrick wrote: > On Feb 2, 2:41 pm, Corey Richardson wrote: > > > I don't recall ever doing anything but injecting my honest opinion. If > > my opinion may be flawed (or appears to be flawed, I usually don't > > elaborate on my ideas enough), so be it. > > Yes you are correct. When i added you to the troll list that was by > accident. You are obviously not a troll and probably not a flamer > either. Anyone willing to offer help is a moderate so there you go... > You were retorting (in kind) to a post by *not* Corey, then promptly dropped him in *your* flamer category. > > py> moderate_group.append(flamer_group.pop("Corey Richardson")) > > > Will you be forking IDLE and setting up some sort of tracker for > > improvements? > > No because we already have a bug tracker set up for IDLE. Why create > another one? We just need the "powers that be" to start accepting > major changes to the IDLE library at hand. There is not even enough > interest to get minor changes committed. A fork would be the best idea > however i am not going to start it alone. If someone else wants to > start a fork be my guest, i will be happy to help out once the fork is > established. > Why not start the fork yourself? Do you think that it will not be accepted after you've sunk time into the project? This sounds like someone who is not convinced the project is worth doing in the first place. Also, consider it a slight element of risk. Lots of people have written code that has ultimately found no (or little) use; you call for wide, sweeping changes to the IDLE code base yet require someone else to actually make the leap before you do. Visionaries don't call for something, then wait for someone to start it before jumping on the bandwagon (i.e. MLK...). > > However i am always very reluctant to start these things because the > powers that be have not even expressed even the *smallest* interest in > change. Sure Raymond, and Terry are interested but how about the > others? We have yet to hear from the other BIG players. All we have > gotten so far is trolling, threating, and negativity from a few very > loud naysayers. > Perhaps they haven't expressed any interest in change because they have no vested interest in it. Where's the interest if you don't use IDLE at all? I have never once used it (I did open it up for the first time at the start of the thread to see what it was, even), but its existence/non-existence makes no difference in my daily usage/preference for anything python. You could remove IDLE altogether and I'd not have noticed. VIM provides me with all the syntax highlighting I need. I'll admit that it's sometimes more convenient to have an interactive python shell that supports syntax highlighting, but IDLE does that just fine. The way I see it, if it works for what it's needed for and you're overall uninterested in its source code, you have little stake in spending any time on it. I think you'd be mad to try and learn Tkinter by looking in idlelib, anyway; even if the code wasn't so crufty. > Now, after all this uphill battle i have fought only two brave souls > (Corey and Richard) have showed an interest in actually doing > something. And believe me i thank them! These are great people! But > were is the blessing from on high? Where is Steve Holden on this? Is > he too busy with $295.00 per session O-Reilly classes to stop by and > give his blessing. Were is py-dev on this? I know these folks have > This is probably not important to them (or they're still recovering from your Tkinter roast and don't want to look at another roast of a project that uses said package you so publicly berated). They're not required to have a vested interest in anything and everything falling inside stdlib. It's still quite large, as much as they try to keep it lean. > *real* work to do however a quick "we're with you guys!", or a simple > http://www.urbandictionary.com/define.php?term=fishing%20for%20compliments > "break a leg!" would be very helpful. > If *we* were to dig up your previous posts (here and on Tkinter), we'd see numerous examples where you've been told almost this very thing, only to have you question "why you deserved such treatment". (Who knows what *we* means) > Are we not worthy of a simple: > > "Yes, improving IDLE's code base sounds good to me." > I don't think *improving* anything ever sounds bad to anyone. ever. Therefore, you're simply left with trying to convince people that the *changes* are really *improvements*. > > or a simple: > > "Sorry, i don't think we should worry about that because X,Y,Z." > > Come on Guido we need your input already! If some big players would > show even the smallest support for improving IDLE (or any module) then > that positivity would propagate down to the rest of us. The naysayers > would stop trolling and the silent majority would start getting > involved. > How do you know that such a majority exists if it is silent? As it has yet to be *observed*, said majority neither exists nor *doesn't exist*, but is instead in some superposition state of existential existence. Only through the act of observation and measurement can an object be said to exist at all, as only then is it forced into some observable eigenstate. At least according to the laws of the universe as we understand them today. (we = physicists/scientists) But if you DO upgrade/update/improve/replace IDLE, I like the way the in-terminal interpreter pipes help(module) output through less rather than barfing it on the screen; the only IDLE shortcoming I've encountered in my 30 seconds of tinkering. Perhaps this behavior is just Unix-specific, though, and I'm perfectly content to continue playing in my terminal. Happy trolling, Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at boddie.org.uk Wed Feb 2 18:56:42 2011 From: david at boddie.org.uk (David Boddie) Date: Thu, 03 Feb 2011 00:56:42 +0100 Subject: PyQT: QWebView with custom QNetworkAccessManager References: Message-ID: On Wednesday 02 February 2011 00:31, Gelonida wrote: > I would like to subclass QNetworkAccessManager and > create a subclass of QWebView, that will use the subclassed > QNetworkAccessManager for all accesses. > > Is this possible? > I have really no idea when and how I could achieve this. > > Thanks in advance for any suggestions / pointers See this page for an example: http://www.diotavelli.net/PyQtWiki/Using_a_Custom_Protocol_with_QtWebKit Try subclassing the NetworkAccessManager.createRequest method as in the example and returning custom replies for each access. That might do what you want. David From steve+comp.lang.python at pearwood.info Wed Feb 2 20:08:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Feb 2011 01:08:37 GMT Subject: Perl Hacker, Python Initiate References: <87sjw7vxt6.fsf@benfinney.id.au> Message-ID: <4d4a0015$0$29991$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 Feb 2011 11:00:11 -0500, Gary Chambers wrote: > Finally, the problem I encountered in the Python code was having the > script fail when it encountered a line that didn't match either of the > two regular expressions. What I'm seeking is either some Python code > that mimics what my Perl script is doing, or to be shown the Python way > of how to accomplish something like that. I'd start with something like this: lines = ... # wherever you are getting your input from for line in lines: if condition1(line): process1(line) elif condition2(line): process2(line) If neither condition1 nor condition2 are true, the loop will just go onto the next line. Obviously the condition* and process* are just place- holders. > Surprisingly, there's no > mention of regular expressions in the Perl Phrasebook at > http://wiki.python.org/moin/PerlPhrasebook. Perhaps your browser's "find" command is broken, because I count nine matches. I don't know if any of them are useful or not. The basic technique for using regular expressions in Python is: import re # regexes are not built-in mo = re.search(r"\b\w*ish\b", "Nobody expects the Spanish Inquisition!") if mo is not None: mo.group() => 'Spanish' You don't have to use raw string r"", you can manually escape the backslashes: r"\b\w*ish\b" <=> "\\b\\w*ish\\b" -- Steven From billy.earney at gmail.com Wed Feb 2 21:58:15 2011 From: billy.earney at gmail.com (Billy Earney) Date: Wed, 2 Feb 2011 20:58:15 -0600 Subject: looking for new members to join grid of storage nodes using tahoe-lafs which is implemented in python. Message-ID: Would you like to be able to back up ~1 TB of data to secure, highly-reliable, off-site storage, for free? By "highly-reliable" I mean that your data should survive pretty much anything short of the collapse of civilization. By "free" I mean "no monetary cost, although you have to provide some hardware and a little of your time". There's a very cool distributed file system project implemented in python called Tahoe-LAFS (http://tahoe-lafs.org) . The idea is that when you store files in this file system, they actually get split into multiple pieces and moved to servers "elsewhere" on the Internet. Even better, the splitting is done in such a way that even if some of the pieces get lost or destroyed, your data is still perfectly intact and retrievable at any time. Oh and all of your pieces are encrypted so that no one who has access to the servers hosting them can see your data. Where are these "other servers"? Well, they can be anywhere, but in this case, the server grid that I'm using is provided by a group of volunteers, all of whom want highly-reliable off-site backup storage. The cost of using this grid is that you have to provide a backup server of your own, which will host pieces of other peoples' data. We call it "volunteergrid2". The two is because there's also a "volunteergrid1", which is working fine, but I've found doesn't meet my requirements. Basically, I want to store a lot more stuff than that grid is set up to accept, so I've been pushing for this new grid. Here are the basic requirements to join the grid: 1. You have to have a computer which is always on and always connected to the Internet. In fact, you have to commit to keeping that machine up and connected at least 95% of the time (no more than 8 hours per week or 1.5 days per month downtime). It's easier if the machine runs a Unix operating system, though Windows works, too. 2. You have to provide at least 500 GB of storage to the grid. 3. You have to be able to open a couple of ports through your router/firewall to expose that portion of your server to the Internet. If you need help with this, the members of the grid can probably help. 4. You may consume as much storage from the grid as what you provide to the grid, with one caveat and one issue to consider. The issue is that when your files are split into pieces, depending on the splitting parameters you choose (and we'll be glad to help you make good choices), your files will get larger. So if your parameters cause your files to grow by a factor of three, and you provide 500 GB of storage to the grid, then you can store 170 GB of your data in the grid. The caveat is that there is a 1 TB cap. You may not store more than 1 TB in the grid -- not without approval of the rest of the grid members, anyway. The group makes decisions by consensus. So far, the grid has about 10 storage servers, each contributing 500 GB, for a total of 5 TB. We'd like to get that up to at least 20 servers and 10-15 TB, and I'd really like to get to 40 servers and 30-40 TB, because with more servers you can use more efficient splitting so you get the same level of reliability but with less expansion. Over time, I expect we'll gradually raise the bar, requiring all participants to provide at least 750 GB, then 1 TB, and so on, so that our available storage keeps pace with the growth in common drive capacities. If you are interested, you can find out more information at http://bigpig.org. We have a subscription list which members use as their main line of communication to other members. You can subscribe at http://tahoe-lafs.org/cgi-bin/mailman/listinfo/volunteergrid2-l Billy -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Feb 2 23:01:11 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Feb 2011 20:01:11 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> Message-ID: rantingrick wrote: >Well your statment completely ignores the silent majority. There's a term for people who believe they act with the tacit approval of the majority: megalomania. It's also known as narcissistic personality disorder. > No they are trolls and they have demonstrated trollish behavior on > many occasions. Some have even threatened to kill me. Can you believe > that? No. Link or it did not happen. From wuwei23 at gmail.com Wed Feb 2 23:03:06 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Feb 2011 20:03:06 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: <426141f5-3a2e-46c3-b499-a896469f39eb@e9g2000vbi.googlegroups.com> rantingrick wrote: > Hmm, that coming from someone who has two posts in this group. And the > last he posted was a year ago! Wait, I thought you had the approval of the silent majority? So once anyone actually posts, they lost the right to be counted, because only when they shut up can you consider them allies? From sohel807 at gmail.com Wed Feb 2 23:09:14 2011 From: sohel807 at gmail.com (Akand Islam) Date: Wed, 2 Feb 2011 20:09:14 -0800 (PST) Subject: wxPython's "Print" Help References: <8ad59b6e-8f69-4a90-8de2-9b3ac2e1438a@n18g2000vbq.googlegroups.com> Message-ID: On Feb 2, 3:24?pm, Terry Reedy wrote: > On 2/2/2011 12:36 AM, Akand Islam wrote: > > wxPython has its own mailing list. > > If you prefer newsgroups, like I do, connect to news.gmane.org and > subscribe to comp.lang.python.wxpython. > -- > Terry Jan Reedy Thanks for your response. -- Akand From wuwei23 at gmail.com Wed Feb 2 23:10:39 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Feb 2011 20:10:39 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: rantingrick wrote: > That is all you have brought to this conversion so far. You have not > offered solutions for IDLE, heck you don't even inject an opinion of > IDLE. You just spew bile. Have fun with your new playmates. > > py> flamer_group.append(troll_group.pop("Corey Richardson")) Ah, the hypocrisy. It feels like only a few days ago that I read: > Why is it necessarily for you guys to advertise when you plonk. Just > plonk and shut up about it. Nobody cares what you do with your own > incoming email. Really, are you that self centered as to think we > actually care? Citation: http://goo.gl/LlBFj From wuwei23 at gmail.com Wed Feb 2 23:38:36 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Feb 2011 20:38:36 -0800 (PST) Subject: How can I tell if I am inside a context manager? References: Message-ID: Gerald Britton wrote: > >>> x = f() > >>> hasattr(x, '__enter__') > True > >>> with f() as x: > ? ? ? ? hasattr(x,'__enter__') > True > > As you can see, the object has a '__enter__' method regardless of how > it was created. ?Whatever the test, it needs to return False in the > first case and True in the second case, without modifying the class > definition. If you control all instantiation and this is to simplify code further on, could you have a ContextF that's a child of F? The only difference would then be the protocol methods. A use case could also help here. From mwilson at the-wire.com Wed Feb 2 23:44:13 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 02 Feb 2011 23:44:13 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: alex23 wrote: >> Why is it necessarily for you guys to advertise when you plonk. Just >> plonk and shut up about it. Nobody cares what you do with your own >> incoming email. Really, are you that self centered as to think we >> actually care? > > Citation: http://goo.gl/LlBFj Actually, FWIW, not everybody advertises plonks. Mel. From wuwei23 at gmail.com Wed Feb 2 23:45:46 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Feb 2011 20:45:46 -0800 (PST) Subject: How can I tell if I am inside a context manager? References: Message-ID: <270b5dcb-3637-4265-9a0e-23432d028284@s3g2000vbf.googlegroups.com> On Feb 2, 1:28?am, Gerald Britton wrote: > I'd like to know how (perhaps with the inspect module) I can tell if I > am running in a context manager. Actually, it occurs to me the simplest way is to use the context manager itself to keep track: class F(object): def __init__(self): self.in_context = False def __enter__(self): self.in_context = True return self def __exit__(self, exc_type, exc_val, exc_tb): self.in_context = False >>> f = F() >>> f.in_context False >>> with F() as f: ... print f.in_context ... True >>> print f.in_context False Hope this helps. From oswald.harry at gmail.com Wed Feb 2 23:46:12 2011 From: oswald.harry at gmail.com (harryos) Date: Wed, 2 Feb 2011 20:46:12 -0800 (PST) Subject: os.path.join doubt Message-ID: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> In windows ,I tried this p1 = "C:\Users\me\Documents" p2 = "..\Pictures\images\my.jpg" print os.path.join(p1,p2) This gives 'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' I expected I would get 'C:\\Users\\me\\Pictures\\images\\my.jpg' I thought os.path.join would join the paths more intelligently..Any idea why this happens ? harry From jason.swails at gmail.com Thu Feb 3 00:04:43 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 3 Feb 2011 00:04:43 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: On Wed, Feb 2, 2011 at 11:44 PM, Mel wrote: > alex23 wrote: > > >> Why is it necessarily for you guys to advertise when you plonk. Just > >> plonk and shut up about it. Nobody cares what you do with your own > >> incoming email. Really, are you that self centered as to think we > >> actually care? > > > > Citation: http://goo.gl/LlBFj > > Actually, FWIW, not everybody advertises plonks. > They should. It's a fun word to read. Jason > > Mel. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Feb 3 01:01:25 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 Feb 2011 22:01:25 -0800 Subject: os.path.join doubt In-Reply-To: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> Message-ID: On Wed, Feb 2, 2011 at 8:46 PM, harryos wrote: > In windows ,I tried this > > p1 = "C:\Users\me\Documents" > p2 = "..\Pictures\images\my.jpg" > > print os.path.join(p1,p2) > This gives > 'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' > > I expected I would get > 'C:\\Users\\me\\Pictures\\images\\my.jpg' > > I thought os.path.join would join the paths more intelligently..Any > idea why this happens ? Because that's just not how the function is defined. I admit the "intelligently" descriptor in its docs is fairly vague. Call os.path.normpath() on the join() result to simplify the path and obtain the form you expected. http://docs.python.org/library/os.path.html#os.path.normpath Cheers, Chris -- http://blog.rebertia.com From ershantibhushan at gmail.com Thu Feb 3 01:30:54 2011 From: ershantibhushan at gmail.com (shanti bhushan) Date: Wed, 2 Feb 2011 22:30:54 -0800 (PST) Subject: problem with Sorting from Array Message-ID: <3275a597-bcff-4d93-b767-6400af0c8a62@s11g2000yqh.googlegroups.com> Dear All, funtion "textPosValue " will give me key ,type and pos values from the arrays. This an embedded application code . I want to execute some thing when key ==0 && type ==0 please let me know where to put such code i am getting confused with it def textPosValue(data): str_arr1=[" 0",".@/:1","abc2", "def3","ghi4", "jkl5","mno6", "pqrs7","tuv8", "wxyz9" ] str_arr2=[" 0",".@/:1","ABC2", "DEF3","GHI4", "JKL5","MNO6", "PQRS7","TUV8", "WXYZ9" ] str_arr3=["0","1","2", "3","4","5", "6","7","8", "9" ] str_arr4=[" 0",".@/:1","?[] 2", "!<> 3",",&\ 4", "()~ 5","'{}` 6", ";$|^ 7","_#% 8", "-*+=9" ] str=[str_arr1,str_arr2,str_arr3,str_arr4] k=1 first=0 SecPos=0 sts=0 try: for first in range(4): for SecPos in range(10): # print "first,SecPos,str[first] [Secpos]",first,SecPos,str[first][SecPos] sts=str[first][SecPos].find(data) # print sts if (sts < 0): continue else: k=0 break if (k==0): print sts break return first, SecPos, sts except IndexError: return -1,-1,-1 for ch in "43.88.79.132" : type,key,Pos=textPosValue(ch) for i in range(type): cat,data=remote_keypress("green") send_sircs(cat,data) sleep(0.5) for j in range(Pos+1): if (key ==0 && type ==0) // i want to execute some thing when , key ==0 && type ==0 , is it the right position?? cat,data=remote_keypress("space") send_sircs(cat,data) sleep(0.5) cat,data=remote_keypress("violet") send_sircs(cat,data) sleep(0.5) cat,data=remote_keypress(key) send_sircs(cat,data) sleep(0.5) sleep(0.5) From steve+comp.lang.python at pearwood.info Thu Feb 3 01:31:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Feb 2011 06:31:49 GMT Subject: os.path.join doubt References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> Message-ID: <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 Feb 2011 20:46:12 -0800, harryos wrote: > In windows ,I tried this > > p1 = "C:\Users\me\Documents" > p2 = "..\Pictures\images\my.jpg" > > print os.path.join(p1,p2) > This gives > 'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' > > I expected I would get > 'C:\\Users\\me\\Pictures\\images\\my.jpg' > > I thought os.path.join would join the paths more intelligently..Any idea > why this happens ? You thought wrong. os.path.join just joins what you tell it to, it doesn't normalise the path. If you want to normalise, call os.path.normpath: >>> os.path.normpath('x/y/../z') 'x/z' As for why, it's because joining and normalising are two different operations that you may wish to keep separate, so they require two separate functions. BTW, Windows accepts / as well as \ as a path separator. You will have far fewer headaches if you use that. -- Steven From steve+comp.lang.python at pearwood.info Thu Feb 3 01:47:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Feb 2011 06:47:19 GMT Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> Message-ID: <4d4a4f77$0$29973$c3e8da3$5496439d@news.astraweb.com> On Wed, 02 Feb 2011 20:01:11 -0800, alex23 wrote: > rantingrick wrote: >> No they are trolls and they have demonstrated trollish behavior on many >> occasions. Some have even threatened to kill me. Can you believe that? > > No. Link or it did not happen. Ha ha ha ha, did RR actually say that??? How cute, he thinks "kill file" means murder. Anyway, fun's over... can we all just ignore his childish rants and trolling? You (generic you, not Alex specifically) are only rewarding him for bad behaviour with the attention he craves. If you won't do it for me, do it for your future job prospects. Any future employer who googles you will see you arguing for *days* with a troll. That isn't saying much for your ability to distinguish productive from unproductive tasks :/ Hey Rick, back in June 2010 you promised to fork Python and split the community into the silent majority who support you and the "ivory towers" who disagree with you. How's that working out for you? -- Steven From clp2 at rebertia.com Thu Feb 3 01:59:47 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 Feb 2011 22:59:47 -0800 Subject: problem with Sorting from Array In-Reply-To: <3275a597-bcff-4d93-b767-6400af0c8a62@s11g2000yqh.googlegroups.com> References: <3275a597-bcff-4d93-b767-6400af0c8a62@s11g2000yqh.googlegroups.com> Message-ID: On Wed, Feb 2, 2011 at 10:30 PM, shanti bhushan wrote: > Dear All, > > funtion "textPosValue " will give me key ,type and pos values from the > arrays. > This an embedded application code . > I want to execute some thing when key ==0 && type ==0 please let me > ? ? ? ? ? ? ? ?if (key ==0 && type ==0) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // i want The logical-AND operator in Python is spelled "and", not "&&" as in C-like languages. Also, comments start with a "#", not with "//" (though you probably already know this and seem to have merely had a momentary lapse). I can offer no definitive guidance as to where the conditional belongs due to your code's purpose being rather opaque. I would hazard a guess that it should go near where you change the values of `key` and `type` (since the condition depends upon them) and outside of any nested loop (since you mentioned nothing about repetition). Cheers, Chris -- http://blog.rebertia.com From markus.mj at gmail.com Thu Feb 3 03:15:58 2011 From: markus.mj at gmail.com (Markus) Date: Thu, 3 Feb 2011 00:15:58 -0800 (PST) Subject: parse GET/POST data on simple http server Message-ID: Hi, As a beginner in python, I am looking for example code that would help me understand how to code following idea: 1. Start minimal http server 2. Send GET or POST data (url encoded, or from form) - example Name="Foo" 3. Analyze the GET/POST variable value on server and match to different value example 'if Name = "Foo" then retval = "Bar" ' 4. serve the content of retval back to user as plain html If some code snipped that does implement all or part of the algorithm is known to you, please point me to it. I would be thankful for any push to the right direction. Thank you! From kb1pkl at aim.com Thu Feb 3 03:26:22 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Thu, 03 Feb 2011 03:26:22 -0500 Subject: parse GET/POST data on simple http server In-Reply-To: References: Message-ID: <4D4A66AE.9070605@aim.com> On 02/03/2011 03:15 AM, Markus wrote: > Hi, > > As a beginner in python, I am looking for example code that would help > me understand how to > code following idea: > 1. Start minimal http server > 2. Send GET or POST data (url encoded, or from form) - example > Name="Foo" > 3. Analyze the GET/POST variable value on server and match to > different value > example 'if Name = "Foo" then retval = "Bar" ' > 4. serve the content of retval back to user as plain html > > If some code snipped that does implement all or part of the algorithm > is known to you, please point me to it. I would be thankful for any > push to the right direction. > > Thank you! If you really can't use a 'real' webserver like Apache, I found [1]. Not sure how to use it, never had the need to. The documentation will show you the way, however. Using that and the cgi module, your requirements should be fulfilled. From kb1pkl at aim.com Thu Feb 3 03:26:44 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Thu, 03 Feb 2011 03:26:44 -0500 Subject: parse GET/POST data on simple http server In-Reply-To: References: Message-ID: <4D4A66C4.4000308@aim.com> On 02/03/2011 03:15 AM, Markus wrote: > Hi, > > As a beginner in python, I am looking for example code that would help > me understand how to > code following idea: > 1. Start minimal http server > 2. Send GET or POST data (url encoded, or from form) - example > Name="Foo" > 3. Analyze the GET/POST variable value on server and match to > different value > example 'if Name = "Foo" then retval = "Bar" ' > 4. serve the content of retval back to user as plain html > > If some code snipped that does implement all or part of the algorithm > is known to you, please point me to it. I would be thankful for any > push to the right direction. > > Thank you! [1] http://docs.python.org/library/cgihttpserver.html#module-CGIHTTPServer ...Sorry about that. I shouldn't post late at night! From clp2 at rebertia.com Thu Feb 3 03:35:47 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 3 Feb 2011 00:35:47 -0800 Subject: parse GET/POST data on simple http server In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 12:15 AM, Markus wrote: > Hi, > > As a beginner in python, I am looking for example code that would help > me understand how to > code following idea: > 1. Start minimal http server http://docs.python.org/library/basehttpserver.html http://docs.python.org/library/simplehttpserver.html http://docs.python.org/library/cgihttpserver.html > 2. Send GET or POST data (url encoded, or from form) - example > Name="Foo" http://docs.python.org/library/urllib.html#urllib.urlencode > 3. Analyze the GET/POST variable value on server and match to > different value > ? ?example 'if Name = "Foo" then retval = "Bar" ' http://docs.python.org/library/cgi.html > 4. serve the content of retval back to user as plain html > > If some code snipped that does implement all or part of the algorithm > is known to you, please point me to it. I would be thankful for any > push to the right direction. You'll be reinventing quite a few wheels if you work at such a low level of abstraction. Have you considered using a web framework? Django (http://www.djangoproject.com/ ) is one of the popular ones, though there are a myriad of options (http://wiki.python.org/moin/WebFrameworks ). I would recommend learning Python first and then a web framework, rather than trying to learn both in tandem. Cheers, Chris -- http://blog.rebertia.com From markus.mj at gmail.com Thu Feb 3 03:52:56 2011 From: markus.mj at gmail.com (Markus) Date: Thu, 3 Feb 2011 00:52:56 -0800 (PST) Subject: parse GET/POST data on simple http server References: Message-ID: On Feb 3, 9:35?am, Chris Rebert wrote: > On Thu, Feb 3, 2011 at 12:15 AM, Markus wrote: > > Hi, > > > As a beginner in python, I am looking for example code that would help > > me understand how to > > code following idea: > > 1. Start minimal http server > > http://docs.python.org/library/basehttpserver.htmlhttp://docs.python.org/library/simplehttpserver.htmlhttp://docs.python.org/library/cgihttpserver.html > > > 2. Send GET or POST data (url encoded, or from form) - example > > Name="Foo" > > http://docs.python.org/library/urllib.html#urllib.urlencode > > > 3. Analyze the GET/POST variable value on server and match to > > different value > > ? ?example 'if Name = "Foo" then retval = "Bar" ' > > http://docs.python.org/library/cgi.html > > > 4. serve the content of retval back to user as plain html > > > If some code snipped that does implement all or part of the algorithm > > is known to you, please point me to it. I would be thankful for any > > push to the right direction. > > You'll be reinventing quite a few wheels if you work at such a low > level of abstraction. Have you considered using a web framework? > Django (http://www.djangoproject.com/) is one of the popular ones, > though there are a myriad of options > (http://wiki.python.org/moin/WebFrameworks). I would recommend > learning Python first and then a web framework, rather than trying to > learn both in tandem. > > Cheers, > Chris > --http://blog.rebertia.com Thank you for all that input, I will definitely check Django - it looks very interesting. I just found an example code that fits perfectly and is simple enough for me to play with it. http://stackoverflow.com/questions/336866/how-to-implement-a-minimal-server-for-ajax-in-python And one older post handling the same case with HTTPS: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a1e761a02a852821/2ff6f704b3a6749a?lnk=gst&q=server+parse+post#2ff6f704b3a6749a :o) From redjohn367 at gmail.com Thu Feb 3 04:14:34 2011 From: redjohn367 at gmail.com (Red John) Date: Thu, 3 Feb 2011 01:14:34 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <426141f5-3a2e-46c3-b499-a896469f39eb@e9g2000vbi.googlegroups.com> Message-ID: <9798fcd8-a6f0-457d-90df-0c7a5fafddb7@y31g2000prd.googlegroups.com> On Feb 2, 9:03?pm, alex23 wrote: > rantingrick wrote: > > Hmm, that coming from someone who has two posts in this group. And the > > last he posted was a year ago! > > Wait, I thought you had the approval of the silent majority? > > So once anyone actually posts, they lost the right to be counted, > because only when they shut up can you consider them allies? Lulz, +1 internetz for you From __peter__ at web.de Thu Feb 3 04:24:46 2011 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Feb 2011 10:24:46 +0100 Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> <337dd9ef-4b1f-49f1-b40c-67df7cdbec81@33g2000pru.googlegroups.com> Message-ID: Marc Aymerich wrote: > On Feb 2, 12:11 am, Peter Otten <__pete... at web.de> wrote: >> Marc Aymerich wrote: > Hi!, > Unfortunately per_class attribute losses the "independence" when I try > to mix it with django models.Model . > > from django.db import models > class Plugin(models.base.ModelBase): > class __metaclass__(type): > def __init__(self, *args): > type.__init__(self, *args) > self.per_class = [] > > class BaseService(models.Model): > class Meta: > abstract = True > > __metaclass__ = Plugin > > class VirtualHost(BaseService): > name = models.CharField(max_length=10) > > class SystemUser(BaseService): > name = models.CharField(max_length=10) > > >>>> VirtualHost.per_class is SystemUser.per_class > True > > What am I doing wrong? I'm surprised that you are seeing the per_class-attribute at all as you are defining it in the metaclass of the metaclass, as far as I can tell. I think the following should work: from django.db import models class Plugin(models.base.ModelBase): def __init__(self, *args): super(Plugin, self).__init__(*args) self.per_class = [] class BaseService(models.Model): class Meta: abstract = True __metaclass__ = Plugin class VirtualHost(BaseService): name = models.CharField(max_length=10) class SystemUser(BaseService): name = models.CharField(max_length=10) assert VirtualHost.per_class is not SystemUser.per_class But I have never worked with Django, and the approach based on dictionary lookup is less likely to interfere with the dark corners of the framework. Peter From nobody at nowhere.com Thu Feb 3 04:48:38 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 03 Feb 2011 09:48:38 +0000 Subject: Reassign or discard Popen().stdout from a server process References: Message-ID: On Tue, 01 Feb 2011 08:30:19 +0000, John O'Hagan wrote: > I can't keep reading because that will block - there won't be any more > output until I send some input, and I don't want it in any case. > > To try to fix this I added: > > proc.stdout = os.path.devnull > > which has the effect of stopping the server from failing, but I'm not > convinced it's doing what I think it is. It isn't. os.path.devnull is a string, not a file. But even if you did: proc.stdout = open(os.path.devnull, 'w') that still wouldn't work. > If I replace devnull in the above line with a real file, it stays empty > although I know there is more output, which makes me think it hasn't > really worked. It hasn't. > Simply closing stdout also seems to stop the crashes, but doesn't that mean > it's still being written to, but the writes are just silently failing? In > either case I'm wary of more elusive bugs arising from misdirected stdout. If you close proc.stdout, the next time the server writes to its stdout, it will receive SIGPIPE or, if it catches that, the write will fail with EPIPE (write on pipe with no readers). It's up to the server how it deals with that. > Is it possible to re-assign the stdout of a subprocess after it has started? No. > Or just close it? What's the right way to read stdout up to a given > line, then discard the rest? If the server can handle the pipe being closed, go with that. Otherwise, options include redirecting stdout to a file and running "tail -f" on the file from within Python, or starting a thread or process whose sole function is to read and discard the server's output. From nobody at nowhere.com Thu Feb 3 04:59:28 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 03 Feb 2011 09:59:28 +0000 Subject: os.path.join doubt References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 03 Feb 2011 06:31:49 +0000, Steven D'Aprano wrote: > On Wed, 02 Feb 2011 20:46:12 -0800, harryos wrote: > >> In windows ,I tried this >> >> p1 = "C:\Users\me\Documents" >> p2 = "..\Pictures\images\my.jpg" Don't do this; backslash is significant within Python string literals. If want to use literal backslashes in a string literal, either double them: p1 = "C:\\Users\\me\\Documents" or use a raw literal: p1 = r"C:\Users\me\Documents" You got away with it because backslash is only significant when followed by specific characters, none of which occurred in this case. > BTW, Windows accepts / as well as \ as a path separator. You will have > far fewer headaches if you use that. Unless you need to pass strings to the command interpreter, which has its own interpretation of forward slashes. Apart from that, while forward slashes are supported by Windows itself, they aren't the "standard" separator, and may not be supported by other programs running on Windows. In general, directory separators shouldn't occur within string literals. Base directories should be taken from command-line parameters, registry entries, configuration files, environment variables etc, not embedded into the program. Paths relative to those directories should be constructed with os.path.join(). From glicerinu at gmail.com Thu Feb 3 05:13:46 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Thu, 3 Feb 2011 02:13:46 -0800 (PST) Subject: DRY and static attribute for multiple classes. References: <31da8b4d-51e6-4e5a-bf7c-67ce1d25aaa3@r4g2000prm.googlegroups.com> <337dd9ef-4b1f-49f1-b40c-67df7cdbec81@33g2000pru.googlegroups.com> Message-ID: <700535cb-2249-484c-876c-9de535544ba7@r19g2000prm.googlegroups.com> On Feb 3, 10:24?am, Peter Otten <__pete... at web.de> wrote: > Marc Aymerich wrote: > > On Feb 2, 12:11 am, Peter Otten <__pete... at web.de> wrote: > >> Marc Aymerich wrote: > > Hi!, > > Unfortunately per_class attribute losses the "independence" when I try > > to mix it with django models.Model . > > > from django.db import models > > class Plugin(models.base.ModelBase): > > ? ? class __metaclass__(type): > > ? ? ? ? def __init__(self, *args): > > ? ? ? ? ? ? type.__init__(self, *args) > > ? ? ? ? ? ? self.per_class = [] > > > class BaseService(models.Model): > > ? ? class Meta: > > ? ? ? ? abstract = True > > > ? ? __metaclass__ = Plugin > > > class VirtualHost(BaseService): > > ? ? name = models.CharField(max_length=10) > > > class SystemUser(BaseService): > > ? ? name = models.CharField(max_length=10) > > >>>> VirtualHost.per_class is SystemUser.per_class > > True > > > What am I doing wrong? > > I'm surprised that you are seeing the per_class-attribute at all as you are > defining it in the metaclass of the metaclass, as far as I can tell. > I think the following should work: > > from django.db import models > > class Plugin(models.base.ModelBase): > ? ? def __init__(self, *args): > ? ? ? ? super(Plugin, self).__init__(*args) > ? ? ? ? self.per_class = [] > > class BaseService(models.Model): > ? ? class Meta: > ? ? ? ? abstract = True > > ? ? __metaclass__ = Plugin > > class VirtualHost(BaseService): > ? ? name = models.CharField(max_length=10) > > class SystemUser(BaseService): > ? ? name = models.CharField(max_length=10) > > assert VirtualHost.per_class is not SystemUser.per_class > > But I have never worked with Django, and the approach based on dictionary > lookup is less likely to interfere with the dark corners of the framework. > > Peter Wow Peter, thanks for the correction, I've never used a metaclass before :) With your correction seems that it works perfectly on djando >>> VirtualHost._plugin_registry.append('0000000') >>> VirtualHost._plugin_registry ['0000000'] >>> SystemUser._plugin_registry [] >>> From matt.j.warren at gmail.com Thu Feb 3 05:22:54 2011 From: matt.j.warren at gmail.com (AlienBaby) Date: Thu, 3 Feb 2011 02:22:54 -0800 (PST) Subject: locale settings and date parsing under windows Message-ID: Hi, I'm attempting to convert some date-time strings from a text file under windows into a datetime object as returned by strptime() However, the strings can represent dates in various formats based on the country of origin, for example shortened month names etc.. are different between countries. I am trying to set the correct locale for strptime to work, but I'm having a lot of trouble doing this under windows. IE, wher the date is in the Danish Language, import locale locale.setlocale('LC_ALL',locale.normalize('da_DK')) gives locale.Error: unsupported locale string. I have tried various ways but always hit the same error. I understand setting LC_ALL may not be what I require, I was first looking to simply get the locale setting correctly before I started changing only the date-time specific elements. Any help or pointers much appreciated. Current searching around is revealing a fair amount of confusion..! Thanks, Matt. From flebber.crue at gmail.com Thu Feb 3 05:29:18 2011 From: flebber.crue at gmail.com (flebber) Date: Thu, 3 Feb 2011 02:29:18 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: Message-ID: <30c1a682-f26c-43fe-9e13-ef8e8556dc92@i14g2000prm.googlegroups.com> On Feb 1, 11:38?pm, rantingrick wrote: > On Feb 1, 4:20?am, flebber wrote: > > > Sorry Rick too boring....trying to get bored people to bite at your > > ultra lame post yawn........... > > Well reality and truth both has a tendency to be boring. Why? Well > because we bathe in them daily. We have come accustomed, acclimated, > and sadly complacent of the ill state of our stdlib. Yes, boring. > However we must be aware of these things. Yes but fixing idle just gives us another editor, there isn't a shortage of editors. There is a shortage of a common community code base for an ide framework, logical, reusable and extensible. For an example of a brilliant beginners "ide" racket has it covered with DrRacket http://racket-lang.org/ , it has selectable language levels beginner, intermediate, advanced that allows the learner to adjust the level of language features available as they learn, teachpacks are installable to add extra features or options when completing the tutorials(could easily be adapted to the python tutorials). If idle is for teaching people to learn python shouldn't it have the facility to do that? From jeanmichel at sequans.com Thu Feb 3 05:31:50 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 Feb 2011 11:31:50 +0100 Subject: Style question: Nicknames for deeply nested objects In-Reply-To: References: <4D4699C1.7090206@sequans.com> Message-ID: <4D4A8416.1070004@sequans.com> Gerald Britton wrote: >> >> however, considering what >> >> "import a.module.that.is.quite.nested as myModule" >> > > Won't work since I get the objects at run time > > > myModule = __import__('whatever.module.imported.at.run.time', globals(), locals(), [], -1) See http://docs.python.org/library/functions.html#__import__ JM From matt.j.warren at gmail.com Thu Feb 3 05:59:28 2011 From: matt.j.warren at gmail.com (AlienBaby) Date: Thu, 3 Feb 2011 02:59:28 -0800 (PST) Subject: locale settings and date parsing under windows References: Message-ID: <4496c00f-4b40-4426-88eb-07bed89532fb@m16g2000prc.googlegroups.com> On Feb 3, 10:22?am, AlienBaby wrote: > Hi, > > I'm attempting to convert some date-time strings from a text file > under windows into a datetime object as returned by strptime() > > However, the strings can represent dates in various formats based on > the country of origin, for example shortened month names etc.. are > different between countries. > > I am trying to set the correct locale for strptime to work, but I'm > having a lot of trouble doing this under windows. > > IE, wher the date is in the Danish Language, > > import locale > locale.setlocale('LC_ALL',locale.normalize('da_DK')) > > gives > > locale.Error: unsupported locale string. > > I have tried various ways but always hit the same error. > > I understand setting LC_ALL may not be what I require, I was first > looking to simply get the locale setting correctly before I started > changing only the date-time specific elements. > > Any help or pointers much appreciated. Current searching around is > revealing a fair amount of confusion..! > > Thanks, > > Matt. As often happens, writing that out and the working through a bit more, I resolved my own question. It ended up being a simple matter of translating from posix codes to windows codes, so 'fr_FR' becomes 'French_France'... thanks, MAtt. From martin.hellwig at dcuktec.org Thu Feb 3 07:13:20 2011 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 03 Feb 2011 12:13:20 +0000 Subject: locale settings and date parsing under windows In-Reply-To: <4496c00f-4b40-4426-88eb-07bed89532fb@m16g2000prc.googlegroups.com> References: <4496c00f-4b40-4426-88eb-07bed89532fb@m16g2000prc.googlegroups.com> Message-ID: On 02/03/11 10:59, AlienBaby wrote: > On Feb 3, 10:22 am, AlienBaby wrote: >> Hi, >> >> I'm attempting to convert some date-time strings from a text file >> under windows into a datetime object as returned by strptime() >> >> However, the strings can represent dates in various formats based on >> the country of origin, for example shortened month names etc.. are >> different between countries. >> >> I am trying to set the correct locale for strptime to work, but I'm >> having a lot of trouble doing this under windows. >> >> IE, wher the date is in the Danish Language, >> >> import locale >> locale.setlocale('LC_ALL',locale.normalize('da_DK')) >> >> gives >> >> locale.Error: unsupported locale string. >> >> I have tried various ways but always hit the same error. >> >> I understand setting LC_ALL may not be what I require, I was first >> looking to simply get the locale setting correctly before I started >> changing only the date-time specific elements. >> >> Any help or pointers much appreciated. Current searching around is >> revealing a fair amount of confusion..! >> >> Thanks, >> >> Matt. > > As often happens, writing that out and the working through a bit more, > I resolved my own question. > > It ended up being a simple matter of translating from posix codes to > windows codes, so 'fr_FR' becomes 'French_France'... > > thanks, > > MAtt. You might also want to have a look at the contents of: locale.locale_alias -- mph From matt.j.warren at gmail.com Thu Feb 3 07:23:21 2011 From: matt.j.warren at gmail.com (AlienBaby) Date: Thu, 3 Feb 2011 04:23:21 -0800 (PST) Subject: locale settings and date parsing under windows References: <4496c00f-4b40-4426-88eb-07bed89532fb@m16g2000prc.googlegroups.com> Message-ID: <3ce79758-e96b-4e06-8717-d443fad9f0b5@n2g2000pre.googlegroups.com> On Feb 3, 12:13?pm, "Martin P. Hellwig" wrote: > On 02/03/11 10:59, AlienBaby wrote: > > > > > > > On Feb 3, 10:22 am, AlienBaby ?wrote: > >> Hi, > > >> I'm attempting to convert some date-time strings from a text file > >> under windows into a datetime object as returned by strptime() > > >> However, the strings can represent dates in various formats based on > >> the country of origin, for example shortened month names etc.. are > >> different between countries. > > >> I am trying to set the correct locale for strptime to work, but I'm > >> having a lot of trouble doing this under windows. > > >> IE, wher the date is in the Danish Language, > > >> import locale > >> locale.setlocale('LC_ALL',locale.normalize('da_DK')) > > >> gives > > >> locale.Error: unsupported locale string. > > >> I have tried various ways but always hit the same error. > > >> I understand setting LC_ALL may not be what I require, I was first > >> looking to simply get the locale setting correctly before I started > >> changing only the date-time specific elements. > > >> Any help or pointers much appreciated. Current searching around is > >> revealing a fair amount of confusion..! > > >> Thanks, > > >> Matt. > > > As often happens, writing that out and the working through a bit more, > > I resolved my own question. > > > It ended up being a simple matter of translating from posix codes to > > windows codes, so 'fr_FR' becomes 'French_France'... > > > thanks, > > > MAtt. > > You might also want to have a look at the contents of: > locale.locale_alias > > -- > mph- Hide quoted text - > > - Show quoted text - I did for a bit.. I tried, for example with French from locale.locale_alias, you can find 'fr_FR' aliases to 'fr_FR.ISO8859-1' but trying, locale.setlocale(locale.LC_ALL,'fr_FR.ISO8859-1') gives locale.Error: unsupported locale setting I'm now just using a handbuilt dict that holds translations like 'fr_FR' : 'French_France' 'da_DK' : 'Danish_Denmark' etc.. Thanks, MAtt. From benjamin.kaplan at case.edu Thu Feb 3 08:10:10 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 3 Feb 2011 08:10:10 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <30c1a682-f26c-43fe-9e13-ef8e8556dc92@i14g2000prm.googlegroups.com> References: <30c1a682-f26c-43fe-9e13-ef8e8556dc92@i14g2000prm.googlegroups.com> Message-ID: On Thu, Feb 3, 2011 at 5:29 AM, flebber wrote: > On Feb 1, 11:38?pm, rantingrick wrote: >> On Feb 1, 4:20?am, flebber wrote: >> >> > Sorry Rick too boring....trying to get bored people to bite at your >> > ultra lame post yawn........... >> >> Well reality and truth both has a tendency to be boring. Why? Well >> because we bathe in them daily. We have come accustomed, acclimated, >> and sadly complacent of the ill state of our stdlib. Yes, boring. >> However we must be aware of these things. > > Yes but fixing idle just gives us another editor, there isn't a > shortage of editors. There is a shortage of a common community code > base for an ide framework, logical, reusable and extensible. > > For an example of a brilliant beginners "ide" racket has it covered > with DrRacket http://racket-lang.org/ , it has selectable language > levels beginner, intermediate, advanced that allows the learner to > adjust the level of language features available as they learn, > teachpacks are installable to add extra features or options when > completing the tutorials(could easily be adapted to the python > tutorials). If idle is for teaching people to learn python shouldn't > it have the facility to do that? Python is a general purpose language that's designed to be easy to use. Racket is a language that was designed for teaching programming. It's almost exclusively tied to a single IDE. Something like language levels would be impossible to do in Python unless you re-do the parser. There's no feature that allows you to strip for loops or list comprehensions out of the language. And we already have something better than teachpacks- the import mechanism and the ability to install 3rd party extensions. > -- > http://mail.python.org/mailman/listinfo/python-list > From python at bdurham.com Thu Feb 3 08:24:17 2011 From: python at bdurham.com (python at bdurham.com) Date: Thu, 03 Feb 2011 08:24:17 -0500 Subject: locale settings and date parsing under windows In-Reply-To: <3ce79758-e96b-4e06-8717-d443fad9f0b5@n2g2000pre.googlegroups.com> References: <4496c00f-4b40-4426-88eb-07bed89532fb@m16g2000prc.googlegroups.com> <3ce79758-e96b-4e06-8717-d443fad9f0b5@n2g2000pre.googlegroups.com> Message-ID: <1296739457.25531.1418751597@webmail.messagingengine.com> Matt, > I'm now just using a handbuilt dict that holds translations like > > 'fr_FR' : 'French_France' > 'da_DK' : 'Danish_Denmark' What sources are you using for your dict keys and dict values? I'm struggling with the same issue and I'm looking for master references for both sets of code. Thank you, Malcolm From anikom15 at gmail.com Thu Feb 3 09:24:44 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 03 Feb 2011 06:24:44 -0800 Subject: os.path.join doubt In-Reply-To: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> Message-ID: <1296743084.15766.3.camel@localhost.localdomain> 'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' is a valid path. .. means parent, not 'go back a directory'. But you should really be trying this: p1 = os.environ['HOMEPATH'] p2 = os.path.join(p1, 'Pictures', 'images', 'my.jpg') On Wed, 2011-02-02 at 20:46 -0800, harryos wrote: > In windows ,I tried this > > p1 = "C:\Users\me\Documents" > p2 = "..\Pictures\images\my.jpg" > > print os.path.join(p1,p2) > This gives > 'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' > > I expected I would get > 'C:\\Users\\me\\Pictures\\images\\my.jpg' > > I thought os.path.join would join the paths more intelligently..Any > idea why this happens ? > harry > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.ibmgsi at gmail.com Thu Feb 3 10:21:19 2011 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Thu, 3 Feb 2011 20:51:19 +0530 Subject: Errors while using strip and remove on a variable. Message-ID: Hi, I am trying to strip a string and then remove on the resulting list to remove a set of characters. It works fine with the python shell. But after remove the list becomes None, when i am running it from within a script. I am guessing it has something to do with the way python handles assignment. please find the script below* a ='oe,eune,eueo, ,u' b = a.split(',') print b c = b.remove('oe') print a print c ============================================== Anand Jeyahar http://sites.google.com/a/cbcs.ac.in/students/anand ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Thu Feb 3 10:29:13 2011 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 03 Feb 2011 07:29:13 -0800 Subject: Errors while using strip and remove on a variable. In-Reply-To: References: Message-ID: <4D4AC9C9.10504@islandtraining.com> On 02/03/2011 07:21 AM, anand jeyahar wrote: > Hi, > I am trying to strip a string and then remove on the resulting > list to remove a set of characters. It works fine with the python shell. > > But after remove the list becomes None, when i am running it from > within a script. > > I am guessing it has something to do with the way python handles > assignment. > please find the script below* > > a ='oe,eune,eueo, ,u' > b = a.split(',') > print b > c = b.remove('oe') > print a > > print c > On a list, the "remove" method does not create and return a new list -- instead it removes the element from the list in place. In your code, you "print a" and "print c", but you should have done "print b", where you will find the result you expect. Gary Herron > > ============================================== > Anand Jeyahar > http://sites.google.com/a/cbcs.ac.in/students/anand > ============================================== > The man who is really serious, > with the urge to find out what truth is, > has no style at all. He lives only in what is. > ~Bruce Lee > > Love is a trade with lousy accounting policies. > ~Aang Jie > From benjamin.kaplan at case.edu Thu Feb 3 10:30:51 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 3 Feb 2011 10:30:51 -0500 Subject: Errors while using strip and remove on a variable. In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 10:21 AM, anand jeyahar wrote: > Hi, > ??? I am trying to strip a string and then remove on the resulting list to > remove a set of characters. It works fine with the python shell. > > But after remove the list becomes None, when i am running it from within a > script. > > I am guessing it has something to do with the way python handles assignment. > please find the script below* > > a ='oe,eune,eueo, ,u' > b = a.split(',') > print b > c = b.remove('oe') The remove method of a list modifies the list in place and doesn't return anything (Therefore, it returns None because every function/method in Python has to return something). There's no need to assign the result to a variable. From hniksic at xemacs.org Thu Feb 3 10:41:22 2011 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 03 Feb 2011 16:41:22 +0100 Subject: Perl Hacker, Python Initiate References: Message-ID: <87r5bpcehp.fsf@xemacs.org> Gary Chambers writes: > Will someone please provide some insight on how to accomplish that > task in Python? I am unable to continually (i.e. it stops after > displaying a single line) loop through the output while testing for > the matches on the two regular expressions. Thank you. If I understand you correctly, here is the relevant part (untested): import subprocess, collections dig = subprocess.Popen(["dig", "ns.example.com", "example.com", "axfr"], stdout=subprocess.PIPE).stdout # defaultdict allows the equivalent of push @{$x{$y}}, $z cnames = collections.defaultdict(list) ip = {} for line in dig: if line.startswith(';'): continue # Skip any comments m = re.search(r'regexp1', line) if m: cnames[m.group(2)].append(m.group(1)) # push ... m = re.search(r'regexp2', line) if m: ip[m.group(1)] = m.group(2) From ethan at stoneleaf.us Thu Feb 3 10:58:55 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 03 Feb 2011 07:58:55 -0800 Subject: os.path.join doubt In-Reply-To: <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D4AD0BF.4070907@stoneleaf.us> Steven D'Aprano wrote: > BTW, Windows accepts / as well as \ as a path separator. You will have > far fewer headaches if you use that. Just because Windows accepts / doesn't make it a good idea... Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. --> from glob import glob --> print '\n'.join(glob('c:/temp/*')) c:/temp\0C2O0007.TMP c:/temp\27421 c:/temp\3K540007.TMP c:/temp\AIF19780_01B_BACKUP.DBF c:/temp\Arabic.bin c:/temp\au-descriptor-1.6.0_23-b71.xml c:/temp\AUCHECK_CORE.txt c:/temp\AUCHECK_PARSER.txt c:/temp\bar.py c:/temp\bar.pyc c:/temp\caller.py c:/temp\caller.pyc c:/temp\choose_python.pdf c:/temp\CMD19639_B_BACKUP.DBF c:/temp\COA.pdf c:/temp\compress.py c:/temp\compress.pyc c:/temp\control.dbf c:/temp\control.FPT Or is there an option I'm missing so backslashes are not returned by stdlib functions? ~Ethan~ From rantingrick at gmail.com Thu Feb 3 11:02:22 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 3 Feb 2011 08:02:22 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <30c1a682-f26c-43fe-9e13-ef8e8556dc92@i14g2000prm.googlegroups.com> Message-ID: On Feb 3, 4:29?am, flebber wrote: > For an example of a brilliant beginners "ide" racket has it covered > with DrRackethttp://racket-lang.org/, it has selectable language > levels beginner, intermediate, advanced that allows the learner to > adjust the level of language features available as they learn, > teachpacks are installable to add extra features or options when > completing the tutorials(could easily be adapted to the python > tutorials). If idle is for teaching people to learn python shouldn't > it have the facility to do that? I think it would be a bad idea for us to follow in racket's footsteps. Primarily because these sorts of "handicapping" of the language do not actually help a new user. How is it going to help a beginner by removing certain features? If you don't understand a certain feature then removing the feature does not relieve the confusion. If the philosophy breaks down to "gentle learning curve" then a properly written tutorial is all you need. Ad Python has tons of them! You should read some of Guido's anecdotes about the ABC language where the developers attempted to change "tried and tested" terms to something they thought would be less esoteric for Luddites to learn -- in the end all they accomplished was to propagate more confusion. Multiplicity should never be a feature in programming languages... There should be one-- and preferably only one --obvious way to do it. Actually some could argue that Python breaks this rule many times over and they would be correct! However if you look at a language like Ruby you quickly understand that we rather benign by comparison. However i do believe that IDLE could use a few more beginner enhancements. First, we need to clean up the code base. We cannot keep bolting on features as an afterthought. From sturlamolden at yahoo.no Thu Feb 3 11:12:19 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Thu, 3 Feb 2011 08:12:19 -0800 (PST) Subject: Perl Hacker, Python Initiate References: Message-ID: On 2 Feb, 05:36, Gary Chambers wrote: > Given the following Perl script: (...) Let me quote the deceased Norwegian lisp hacker Erik Naggum: "Excuse me while I barf in Larry Wall's general direction." Sturla From waku at idi.ntnu.no Thu Feb 3 11:18:44 2011 From: waku at idi.ntnu.no (waku) Date: Thu, 3 Feb 2011 08:18:44 -0800 (PST) Subject: Perl Hacker, Python Initiate References: Message-ID: <9804095a-6c16-4b30-8e1b-f5f8b197b7a8@w19g2000yqa.googlegroups.com> you've already got a hint on how to do it using library functions in python. below is a more literal suggestion. On Feb 1, 10:36?pm, Gary Chambers wrote: > All, > > Given the following Perl script: > > #!/usr/bin/perl > > %dig = ( > ? ? ?solaris => "/usr/sbin/dig", > ? ? ?linux ? => "/usr/bin/dig", > ? ? ?darwin ?=> "/usr/bin/dig" > ); dig = {"solaris":"/usr/sbin/dig", "linux":"/usr/bin/dig", "darwin":"/ usr/bin/dig"} > > $DIG = $dig{"$^O"}; dig = dig[os.uname()[0].lower()] > $DOMAIN = "example.com"; > $DNS = "ns.example.com"; domain, dns = ['%sexample.com'%p for p in ('', 'ns.')] # ;) > $DIGCMD = qq/$DIG \@$DNS $DOMAIN axfr/; digcmd = '%s @%s %s axfr' % (dig, dns, domain) > > open DIG, "$DIGCMD|" or die "$DIG: $!\n"; > while () { > ? ? ?next if (/^;/); # Skip any comments > ? ? ?# If we match a CNAME record, we have an alias to something. > ? ? ?# $1 = alias (CNAME), $2 = canonical hostname > ? ? ?if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.${DOMAIN}\.$/) { > ? ? ? ? ?# Push an alias (CNAME) onto an array indexed on canonical hostname > ? ? ? ? ?push(@{$cnames{$2}}, $1); > ? ? ?} > ? ? ?# Here's a standard A (canonical hostname) record > ? ? ?# $1 = canonical hostname, $2 = IPv4 address > ? ? ?if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*A\s+(\S+)$/) { > ? ? ? ? ?$ip{$1} = $2; > ? ? ?}} > > close DIG; lines = [line for line in os.popen(digcmd) if not re.match(';', line)] cname, ip = [re.compile(s.format(domain)) for s in (r'(\S+)\.{0}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.{0}\.$', r'(\S +)\.{0}\.\s+\d+\s+IN\s*A\s+(\S+)$')] cnames, ips = [dict(m.groups() for m in (p.match(l) for l in lines) if m) for p in cname, ip)] the rest is left as an exercise. i did not test this exact code because i don't have your data, but a modified version works on different data. vQ > > # Format and display it like niscat hosts: > # canonicalHostname alias1 [alias2 aliasN] ipAddress > for $host (sort keys %ip) { > ? ? ?print "$host "; > ? ? ?if (defined(@{$cnames{$host}})) { > ? ? ? ? ?print join(' ', @{$cnames{$host}}); > ? ? ? ? ?print " "; > ? ? ?} > ? ? ?print "$ip{$host}\n";} > > exit 0; > > Will someone please provide some insight on how to accomplish that task in > Python? ?I am unable to continually (i.e. it stops after displaying a single > line) loop through the output while testing for the matches on the two > regular expressions. ?Thank you. > > -- Gary Chambers From grahn+nntp at snipabacken.se Thu Feb 3 11:26:05 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 3 Feb 2011 16:26:05 GMT Subject: Perl Hacker, Python Initiate References: Message-ID: On Wed, 2011-02-02, Gary Chambers wrote: > All, > > Given the following Perl script: > > #!/usr/bin/perl I'm a Perl user, but I generally refuse to read Perl code which doesn't utilize 'use warnings/-w' and 'use strict'. There are just too many crazy bugs and 1980s constructs which go unnoticed without them. > %dig = ( > solaris => "/usr/sbin/dig", > linux => "/usr/bin/dig", > darwin => "/usr/bin/dig" > ); Not related to your question, except that you'll have to deal with this in Python too: I really suggest letting the user's $PATH decide which dig to call. /usr/bin is always in the path. /usr/sbin may not be, but if that's a problem for your users, just let your script start by appending it to the pre-existing $PATH. You don't even have to do OS detection on that one -- it's safe to do everywhere. /Jorgen -- // Jorgen Grahn O o . From aarora99 at gmail.com Thu Feb 3 11:27:21 2011 From: aarora99 at gmail.com (Anjali Arora) Date: Thu, 3 Feb 2011 11:27:21 -0500 Subject: 'Upload a valid image' errors with PIL 1.1.7/ Python 2.6/ Mac 10.6.2 Message-ID: Hi, I am struggling with this for the past 2 days: first I got the above error, & googled around to find that I needed the libjpeg module as well, so I re-installed the lot, first libjpeg & then PIL; got a couple errors like JPEG decoder not available etc, fixed that. Now it passes the selftest, but when I try to upload images via the admin site, it throws up the error "Upload a valid image. The file you uploaded was either not an image or a corrupted image." Any help is appreciated. Thanks. -Ara -------------- next part -------------- An HTML attachment was scrubbed... URL: From aarora99 at gmail.com Thu Feb 3 11:30:19 2011 From: aarora99 at gmail.com (Anjali Arora) Date: Thu, 3 Feb 2011 11:30:19 -0500 Subject: Fwd: 'Upload a valid image' errors with PIL 1.1.7/ Python 2.6/ Mac 10.6.2/ Django 1.2.3 Message-ID: I'm sorry, by admin site below, I mean Django Admin site. Hi, I am struggling with this for the past 2 days: first I got the above error, & googled around to find that I needed the libjpeg module as well, so I re-installed the lot, first libjpeg & then PIL; got a couple errors like JPEG decoder not available etc, fixed that. Now it passes the selftest, but when I try to upload images via the admin site, it throws up the error "Upload a valid image. The file you uploaded was either not an image or a corrupted image." Any help is appreciated. Thanks. -Ara -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Feb 3 11:31:44 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 Feb 2011 17:31:44 +0100 Subject: Style question: Nicknames for deeply nested objects In-Reply-To: References: <4D4699C1.7090206@sequans.com> Message-ID: <4D4AD870.7070400@sequans.com> Gerald Britton wrote: > > > Nope. it's nothing to do with imports. It's about objects passed to > methods at run time. Complicated objects with many levels. Not about > modules at all. > Who is providing these objects ? - Your code ? => as said before, you can fix your design with a proper object model - 3rd party libraries ? => I'd be curious to know which one, because they usually do a good job providing a clean minimal public interface. However, do not redesign anything to get only shorter names. You can easily live with that, the way you're doing it is up to you and suggestions have been given. But keep in mind that you should'nt have got nested names that long in the first pace, no matter how complicated the internal implementation. JM From rantingrick at gmail.com Thu Feb 3 12:15:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 3 Feb 2011 09:15:39 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <30c1a682-f26c-43fe-9e13-ef8e8556dc92@i14g2000prm.googlegroups.com> Message-ID: <68ea4e91-a79b-4fa9-9488-599bab595242@r16g2000yqk.googlegroups.com> If anyone would like to see a good example of how IDLE code should be written. I highly suggest you check out the source for PyShell and PyCrust which is located in roughly... HOME\PythonXX\Lib\site-packages\wx-2.8-msw-ansi\wx\py: * shell.py * crust.py * filling.py Also run these scripts to see them all in action: * PyAlaCarte.py * PyAlaMode.py This is a code base that was laid out in a logical and sensible manner. This is a code base that can be built from. IDLE on the other hand is utter chaos. If you don't believe me, first look at the beautiful scripts i mentioned above, then check out these scripts in your idlelib... PythonXX\Lib\idlelib: * EditorWindow.py * PyShell.py It is like night and day people! NIGHT AND DAY!!! From me+list/python at ixokai.io Thu Feb 3 12:50:57 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 03 Feb 2011 09:50:57 -0800 Subject: Errors while using strip and remove on a variable. In-Reply-To: References: Message-ID: <4D4AEB01.5000301@ixokai.io> On 2/3/11 7:21 AM, anand jeyahar wrote: > Hi, > I am trying to strip a string and then remove on the resulting list > to remove a set of characters. It works fine with the python shell. > > But after remove the list becomes None, when i am running it from within > a script. > > I am guessing it has something to do with the way python handles assignment. > please find the script below* > > a ='oe,eune,eueo, ,u' > b = a.split(',') > print b > c = b.remove('oe') As others have stated, the issue is that b.remove('oe') doesn't return b or a copy of b, but directly modifies b instead. I'll add that you will find that this behavior is consistent throughout the list api: the None is more then just a default thing that's returned when nothing else is returned, but in this case its also meant as a signal to clearly indicate that the list is modified in-place. Every once in awhile someone asks for these methods that modify the list itself to either return self, or return a copy of the list -- and I'm not going to get into that debate -- but the reason for the "None" is to make it so you WILL get errors like the above. You only run into this situation with mutable data-types by the way: strings ALWAYS return a copy or new string, because they can't actually modify the string itself. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From dwayneblind at gmail.com Thu Feb 3 12:56:21 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Thu, 3 Feb 2011 18:56:21 +0100 Subject: socket.rcv timeout while-loop Message-ID: Hi everybody, I am using Python 3.0. I have such a code : b=time.clock() while time.clock()-b<3 : data=s.recv(1024) However I would like to set timeout on the socket rcv method, so that the while loop stops exactly after 3 seconds. Is this possible ? Thanks a lot, Dwayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Thu Feb 3 13:04:08 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 03 Feb 2011 10:04:08 -0800 Subject: socket.rcv timeout while-loop In-Reply-To: References: Message-ID: <4D4AEE18.5050301@ixokai.io> On 2/3/11 9:56 AM, Dwayne Blind wrote: > However I would like to set timeout on the socket rcv method, so that > the while loop stops exactly after 3 seconds. Is this possible ? I rarely do low-level socket stuff -- but I think s.settimeout() is what you're looking for. It applies to the whole socket, and not just one method -- so you may want to reset it after you're done recv'n. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From eric.frost at mp2kmag.com Thu Feb 3 13:10:40 2011 From: eric.frost at mp2kmag.com (Eric Frost) Date: Thu, 3 Feb 2011 12:10:40 -0600 Subject: New article on grabbing city points from geonames, processing with Python, and rendering in MapPoint Message-ID: Add City Coverage to MapPoint using the GeoNames Database by Richard Marsden http://www.mapforums.com/add-city-coverage-mappoint-using-geonames-database-15244.html -- m: 312-399-1586 http://www.MapForums.com http://www.MP2Kmag.com From dwayneblind at gmail.com Thu Feb 3 13:13:37 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Thu, 3 Feb 2011 19:13:37 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: <4D4AEE18.5050301@ixokai.io> References: <4D4AEE18.5050301@ixokai.io> Message-ID: Thanks for your answer. I don't want to reset my socket. I want to apply the timeout to the rcv method only. What about select ? http://docs.python.org/library/select.html#select.select How to implement it ? Thanks a lot, Dwayne 2011/2/3 Stephen Hansen > On 2/3/11 9:56 AM, Dwayne Blind wrote: > > However I would like to set timeout on the socket rcv method, so that > > the while loop stops exactly after 3 seconds. Is this possible ? > > I rarely do low-level socket stuff -- but I think s.settimeout() is what > you're looking for. It applies to the whole socket, and not just one > method -- so you may want to reset it after you're done recv'n. > > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fzadrozny at appcelerator.com Thu Feb 3 13:17:12 2011 From: fzadrozny at appcelerator.com (Fabio Zadrozny) Date: Thu, 3 Feb 2011 16:17:12 -0200 Subject: Pydev 1.6.5 Released Message-ID: Hi All, Pydev 1.6.5 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Syntax highlighting now has options to have {}, [] and () as well as operators in different colors * Code generation for classes and methods: Note that this is an initial implementation of the idea, aimed as those that use a TDD (Test Driven Development) approach, so, one can create the test first and generate the classes/methods later on from using shortcuts or quick-fixes (which is something that those using JDT -- Java Development Tools -- in Eclipse should be already familiar with). This feature should be already usable on a number of situations but it's still far from being 100% complete. * Alt+Shift+S C can be used to create a class for the currently selected token * Alt+Shift+S M can be used to create a method for the currently selected token * Ctrl+1 has as a quick fix for creating a class or method * Debugger * When discovering encoding on Python 3.x, the file is opened as binary * Remote debugger (pydevd.settrace()) properly synchronized * Fixed debugger issue on interpreter shutdown on Python 2.7 * Bug fixes: * Fixed issue when doing code-completion on a line that started with some token that started with 'import'. e.g.: import_foo = a * Fixed import when running unittest with coverage * Fixed extract local (could extract to wrong location) * Fixed NPE when requesting print of arguments in the context-information tooltips * Fixed AttributeError with pydevconsole on Python 3.x What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/ Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From me+list/python at ixokai.io Thu Feb 3 13:53:01 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 03 Feb 2011 10:53:01 -0800 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> Message-ID: <4D4AF98D.1060706@ixokai.io> On 2/3/11 10:13 AM, Dwayne Blind wrote: > Thanks for your answer. I don't want to reset my socket. I want to apply > the timeout to the rcv method only. Setting the timeout does not "reset [your] socket", I don't think. And I get that you want to only timeout recv... that's why I pointed out its a socket method, not an argument to recv. If you don't want it to apply to everything else, you just have to be sure to change it back after recv. Just: timeout = s.gettimeout() s.settimeout(3) s.recv(1024) s.settimeout(timeout) Personally, I'd prefer to do: with timeout(s, 3): s.recv(1024) That's a lot more clear, and I'd roll this context manager to accomplish it: --- start from contextlib import contextmanager @contextmanager def timeout(sock, timeout): old_timeout = sock.gettimeout() sock.settimeout(timeout) try: yield sock finally: sock.settimeout(old_timeout) --- end The contextmanager decorator is an easy/quick way of making a context manager. Everything up until the yield is executed before the 'with' block is run, and everything after the yield is executed after the 'with' block concludes. If the with block throws an exception, it'll be catchable at the yield point. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From invalid at invalid.invalid Thu Feb 3 14:44:02 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 3 Feb 2011 19:44:02 +0000 (UTC) Subject: ptrace vs. python-ptrace Message-ID: I'd like to do some experimentation with the Linux ptrace facility. Before I jump in, I was wondering if anybody has any comments they'd like to offer on the relative merits of ptrace vs. python-ptrace: http://pypi.python.org/pypi/ptrace http://pypi.python.org/pypi/python-ptrace Ptrace appears to have been updated more recently that python-ptrace, but python-ptrace includes some sample applications that probably get me closer to my end-goal. Are the APIs compatible (or at all similar)? -- Grant Edwards grant.b.edwards Yow! On the road, ZIPPY at is a pinhead without a gmail.com purpose, but never without a POINT. From mhearne808 at gmail.com Thu Feb 3 15:32:37 2011 From: mhearne808 at gmail.com (mhearne808[insert-at-sign-here]gmail[insert-dot-here]com) Date: Thu, 3 Feb 2011 12:32:37 -0800 (PST) Subject: returning all matching groups with re.search() Message-ID: Here's a scenario: import re m = re.search('e','fredbarneybettywilma') Now, here's a stupid question: why doesn't m.groups() return ('e','e','e'). I'm trying to figure out how to match ALL of the instances of a pattern in one call - the group() and groups() return subgroups... how do I get my search to get me all of the matching subgroups? From clp2 at rebertia.com Thu Feb 3 15:42:55 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 3 Feb 2011 12:42:55 -0800 Subject: returning all matching groups with re.search() In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 12:32 PM, mhearne808[insert-at-sign-here]gmail[insert-dot-here]com wrote: > Here's a scenario: > > import re > m = re.search('e','fredbarneybettywilma') > > Now, here's a stupid question: > why doesn't m.groups() return ('e','e','e'). Straight from the docs (http://docs.python.org/library/re.html ), emphasis mine: re.search(pattern, string[, flags]) "Scan through string looking for **a** location where the regular expression pattern produces **a** match [...]" Hence, it stops looking after the very first match. > I'm trying to figure out how to match ALL of the instances of a > pattern in one call - the group() and groups() return subgroups... how > do I get my search to get me all of the matching subgroups? I think you want re.finditer() or re.findall(). Cheers, Chris -- http://blog.rebertia.com From benjamin.kaplan at case.edu Thu Feb 3 15:45:55 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 3 Feb 2011 15:45:55 -0500 Subject: returning all matching groups with re.search() In-Reply-To: References: Message-ID: On Thu, Feb 3, 2011 at 3:32 PM, mhearne808[insert-at-sign-here]gmail[insert-dot-here]com wrote: > Here's a scenario: > > import re > m = re.search('e','fredbarneybettywilma') > > Now, here's a stupid question: > why doesn't m.groups() return ('e','e','e'). > > I'm trying to figure out how to match ALL of the instances of a > pattern in one call - the group() and groups() return subgroups... how > do I get my search to get me all of the matching subgroups? m.groups() doesn't give return ('e','e','e') because groups don't mean what you think they mean. Groups are subsections of a regular expression, enclosed by parenthesis. For example: >>> m = re.search('(e)','fredbarneybettywilma') >>> m.groups() ('e',) What you want seem to want is re.findall, not re.search From bthate at gmail.com Thu Feb 3 15:53:50 2011 From: bthate at gmail.com (Bart Thate) Date: Thu, 3 Feb 2011 12:53:50 -0800 (PST) Subject: JSONBOT 0.6.1 RELEASED Message-ID: Hello every human out there ! i'm pleased to announce the release of JSONBOT 0.6.1 FINAL, a release that saw a lot of work into the shell side of things and no changes to GAE. 0.6.1 has the following changes: * the ! char is not used instead of | in a pipeline. This is to make it easier to use a pipeline on mobile phones. * a new commandline interface has been created. You can now do "jsb " .. no need to start up the console app when you have a single command to execute * ? is now used a query character, so things you learn the bot with ! learn can be queried with ? * auto_register and guestasuser config options are now disabled by default * core xmpp parsing code has been rewritten * many more bug fixes. You can grab a copy of the code (tarball or mercurial repo) at http://jsonbot.googlecode.com Hope you enjoy this release as much as i enjoyed making it ;] Have Fun ! Bart About JOSNBOT: JSONBOT is a remote event-driven framework for building bots that talk JSON to each other over XMPP. This distribution provides bots built on this framework for console, IRC, XMPP for the shell and WWW and XMPP for the Google Application engine. JSONBOT is all of the following: a shell console bot a shell IRC bot a shell XMPP bot a Web bot running on Google Application Engine a XMPP bot running on Google Application Engine a Google Wave bot running op Google Application Engine the XMPP bots are used to communicate between bots plugin infrastructure to write your own functionality event driven framework by the use of callbacks From vincent at vincentdavis.net Thu Feb 3 17:14:09 2011 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 3 Feb 2011 15:14:09 -0700 Subject: Download an attachment from an IMAP email Message-ID: I have a few emails I am trying to download from my google account. I seem to be getting the message but each of these messages have an attachment. I don't understand what I ned to do to get and save the attachment to a local file. Here is what I have so far. M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT) rc, resp = M.login('xxxxx at xxxx', 'XXXXX') print rc, resp M.select('[Gmail]/All Mail') M.search(None, 'FROM', 'someone at logitech.com') #M.fetch(121, '(body[header.fields (subject)])') M.fetch(121, '(RFC822)') -- Thanks Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwayneblind at gmail.com Thu Feb 3 18:02:26 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Fri, 4 Feb 2011 00:02:26 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: <4D4AF98D.1060706@ixokai.io> References: <4D4AEE18.5050301@ixokai.io> <4D4AF98D.1060706@ixokai.io> Message-ID: Thanks Stephen. It's really nice of you. I have not understood everything though. (I have never used a context manager before.) Here are some comments : timeout = s.gettimeout() # Is that the default timeout ? s.settimeout(3) # I guess this is a 3 second timeout s.recv(1024) s.settimeout(timeout) # You change it back ? So with a while loop, it should be : timeout = s.gettimeout() s.settimeout(3) b=time.clock() while time.clock()-b<3 : data=s.recv(1024) s.settimeout(timeout) Am I right ? Thanks again, Dwayne 2011/2/3 Stephen Hansen > On 2/3/11 10:13 AM, Dwayne Blind wrote: > > Thanks for your answer. I don't want to reset my socket. I want to apply > > the timeout to the rcv method only. > > Setting the timeout does not "reset [your] socket", I don't think. And I > get that you want to only timeout recv... that's why I pointed out its a > socket method, not an argument to recv. If you don't want it to apply to > everything else, you just have to be sure to change it back after recv. > > Just: > timeout = s.gettimeout() > s.settimeout(3) > s.recv(1024) > s.settimeout(timeout) > > Personally, I'd prefer to do: > > with timeout(s, 3): > s.recv(1024) > > That's a lot more clear, and I'd roll this context manager to accomplish > it: > > --- start > > from contextlib import contextmanager > > @contextmanager > def timeout(sock, timeout): > old_timeout = sock.gettimeout() > sock.settimeout(timeout) > try: > yield sock > finally: > sock.settimeout(old_timeout) > > --- end > > The contextmanager decorator is an easy/quick way of making a context > manager. Everything up until the yield is executed before the 'with' > block is run, and everything after the yield is executed after the > 'with' block concludes. > > If the with block throws an exception, it'll be catchable at the yield > point. > > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Feb 3 18:11:08 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Feb 2011 23:11:08 GMT Subject: os.path.join doubt References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d4b360c$0$30000$c3e8da3$5496439d@news.astraweb.com> On Thu, 03 Feb 2011 07:58:55 -0800, Ethan Furman wrote: > Steven D'Aprano wrote: >> BTW, Windows accepts / as well as \ as a path separator. You will have >> far fewer headaches if you use that. > > Just because Windows accepts / doesn't make it a good idea... No. Windows accepting slashes as the alternate path separator *enables* you to use slash. What makes it a good idea is that you don't have to worry about forgetting to escape backslashes: >>> print("C:\temp\file.txt") C: emp ile.txt Nor do you have to care about the fact that raw strings are designed for regular expressions, not Windows path names, and you can't have a raw string ending in a single backslash: >>> location = r'C:\temp\' # Path ending in a backslash. File "", line 1 location = r'C:\temp\' ^ SyntaxError: EOL while scanning string literal The fact is that Windows' use of backslash as the path separator conflicts with Python's use of backslashes. Since our code is written in Python, trying to uses backslashes causes problems. One work-around is to take advantage of the fact that Windows has an alternate separator character, and use that. If you'd rather use raw strings, and special- case backslashes at the end of paths, go right ahead. > --> from glob import glob > --> print '\n'.join(glob('c:/temp/*')) c:/temp\0C2O0007.TMP > c:/temp\27421 > c:/temp\3K540007.TMP [...] Yes. Is there a problem? All those paths should be usable from Windows. If you find it ugly to see paths with a mix of backslashes and forward slashes, call os.path.normpath, or just do a simple string replace: path = path.replace('/', '\\') before displaying them to the user. Likewise if you have to pass the paths to some application that doesn't understand slashes. -- Steven From dwayneblind at gmail.com Thu Feb 3 18:23:07 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Fri, 4 Feb 2011 00:23:07 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> <4D4AF98D.1060706@ixokai.io> Message-ID: The solution would be timeout = s.gettimeout() s.settimeout(3) b=time.clock() while time.clock()-b<3 : try : data=s.recv(1024) except : break s.settimeout(timeout) Am I right ? Dwayne 2011/2/4 Dwayne Blind > Thanks Stephen. It's really nice of you. > > I have not understood everything though. (I have never used a context > manager before.) > > Here are some comments : > > timeout = s.gettimeout() # Is that the default timeout ? > s.settimeout(3) # I guess this is a 3 second timeout > s.recv(1024) > s.settimeout(timeout) # You change it back ? > > So with a while loop, it should be : > > > timeout = s.gettimeout() > s.settimeout(3) > b=time.clock() > while time.clock()-b<3 : > > data=s.recv(1024) > s.settimeout(timeout) > > Am I right ? > > Thanks again, > Dwayne > > > 2011/2/3 Stephen Hansen > >> On 2/3/11 10:13 AM, Dwayne Blind wrote: >> >> > Thanks for your answer. I don't want to reset my socket. I want to apply >> > the timeout to the rcv method only. >> >> Setting the timeout does not "reset [your] socket", I don't think. And I >> get that you want to only timeout recv... that's why I pointed out its a >> socket method, not an argument to recv. If you don't want it to apply to >> everything else, you just have to be sure to change it back after recv. >> >> Just: >> timeout = s.gettimeout() >> s.settimeout(3) >> s.recv(1024) >> s.settimeout(timeout) >> >> Personally, I'd prefer to do: >> >> with timeout(s, 3): >> s.recv(1024) >> >> That's a lot more clear, and I'd roll this context manager to accomplish >> it: >> >> --- start >> >> from contextlib import contextmanager >> >> @contextmanager >> def timeout(sock, timeout): >> old_timeout = sock.gettimeout() >> sock.settimeout(timeout) >> try: >> yield sock >> finally: >> sock.settimeout(old_timeout) >> >> --- end >> >> The contextmanager decorator is an easy/quick way of making a context >> manager. Everything up until the yield is executed before the 'with' >> block is run, and everything after the yield is executed after the >> 'with' block concludes. >> >> If the with block throws an exception, it'll be catchable at the yield >> point. >> >> -- >> >> Stephen Hansen >> ... Also: Ixokai >> ... Mail: me+list/python (AT) ixokai (DOT) io >> ... Blog: http://meh.ixokai.io/ >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anikom15 at gmail.com Thu Feb 3 18:33:34 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 03 Feb 2011 15:33:34 -0800 Subject: os.path.join doubt In-Reply-To: <4d4b360c$0$30000$c3e8da3$5496439d@news.astraweb.com> References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> <4d4b360c$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1296776014.22034.4.camel@localhost.localdomain> On Thu, 2011-02-03 at 23:11 +0000, Steven D'Aprano wrote: > On Thu, 03 Feb 2011 07:58:55 -0800, Ethan Furman wrote: > > > Steven D'Aprano wrote: > >> BTW, Windows accepts / as well as \ as a path separator. You will have > >> far fewer headaches if you use that. > > > > Just because Windows accepts / doesn't make it a good idea... > > No. Windows accepting slashes as the alternate path separator *enables* > you to use slash. What makes it a good idea is that you don't have to > worry about forgetting to escape backslashes: > > >>> print("C:\temp\file.txt") > C: emp > ile.txt > > > Nor do you have to care about the fact that raw strings are designed for > regular expressions, not Windows path names, and you can't have a raw > string ending in a single backslash: > > >>> location = r'C:\temp\' # Path ending in a backslash. > File "", line 1 > location = r'C:\temp\' > ^ > SyntaxError: EOL while scanning string literal > > > The fact is that Windows' use of backslash as the path separator > conflicts with Python's use of backslashes. Since our code is written in > Python, trying to uses backslashes causes problems. One work-around is to > take advantage of the fact that Windows has an alternate separator > character, and use that. If you'd rather use raw strings, and special- > case backslashes at the end of paths, go right ahead. > > > --> from glob import glob > > --> print '\n'.join(glob('c:/temp/*')) c:/temp\0C2O0007.TMP > > c:/temp\27421 > > c:/temp\3K540007.TMP > [...] > > > Yes. Is there a problem? All those paths should be usable from Windows. > If you find it ugly to see paths with a mix of backslashes and forward > slashes, call os.path.normpath, or just do a simple string replace: > > path = path.replace('/', '\\') > > before displaying them to the user. Likewise if you have to pass the > paths to some application that doesn't understand slashes. > > > -- > Steven Paths that mix /s and \s are NOT valid on Windows. In one of the setup.py scripts I wrote I had to write a function to collect the paths of data files for installation. On Windows it didn't work and it was driving me crazy. It wasn't until I realized os.path.join was joining the paths with \\ instead of / that I was able to fix it. def find_package_data(path): """Recursively collect EVERY file in path to a list.""" oldcwd = os.getcwd() os.chdir(path) filelist = [] for path, dirs, filenames in os.walk('.'): for name in filenames: filename = ((os.path.join(path, name)).replace('\\', '/')) filelist.append(filename.replace('./', 'data/')) os.chdir(oldcwd) return filelist -------------- next part -------------- An HTML attachment was scrubbed... URL: From tshinnic at io.com Thu Feb 3 18:57:33 2011 From: tshinnic at io.com (Thomas L. Shinnick) Date: Thu, 03 Feb 2011 17:57:33 -0600 Subject: os.path.join doubt In-Reply-To: <1296776014.22034.4.camel@localhost.localdomain> References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> <4d4b360c$0$30000$c3e8da3$5496439d@news.astraweb.com> <1296776014.22034.4.camel@localhost.localdomain> Message-ID: <3F.53.14011.4F04B4D4@hrndva-omtalb.mail.rr.com> At 05:33 PM 2/3/2011, Westley Mart?nez wrote: >On Thu, 2011-02-03 at 23:11 +0000, Steven D'Aprano wrote: >>On Thu, 03 Feb 2011 07:58:55 -0800, Ethan Furman wrote: >> > Steven D'Aprano wrote: >>[snip] >> >>Yes. Is there a problem? All those paths should be usable from Windows. >>If you find it ugly to see paths with a mix of backslashes and forward >>slashes, call os.path.normpath, or just do a simple string replace: >> >>path = path.replace('/', '\\') >> >>before displaying them to the user. Likewise if you have to pass the >>paths to some application that doesn't understand slashes. >> >> >>-- >>Steven >Paths that mix /s and \s are NOT valid on >Windows. In one of the setup.py scripts I wrote >I had to write a function to collect the paths >of data files for installation. On Windows it >didn't work and it was driving me crazy. It >wasn't until I realized os.path.join was joining >the paths with \\ instead of / that I was able to fix it. > >def find_package_data(path): > """Recursively collect EVERY file in path to a list.""" > oldcwd = os.getcwd() > os.chdir(path) > filelist = [] > for path, dirs, filenames in os.walk('.'): > for name in filenames: > filename = ((os.path.join(path, name)).replace('\\', '/')) > filelist.append(filename.replace('./', 'data/')) > os.chdir(oldcwd) > return filelist Please check out os.path.normpath() as suggested. Example: >>> import os >>> s = r"/hello\\there//yall\\foo.bar" >>> s '/hello\\\\there//yall\\\\foo.bar' >>> v = os.path.normpath(s) >>> v '\\hello\\there\\yall\\foo.bar' The idea behind os.path is to cater to the host OS. Thus os.path.normpath() will convert to the host's acceptable delimiters. That is, you didn't need the .replace(), but rather to more fully use the existing library to good advantage with .normpath(). However, note that delimiters becomes an issue only when directly accessing the host OS, such as when preparing command line calls or accessing native APIs. Within the Python library/environment, both '/' and '\' are acceptable. External use is a different matter. So, you need to be specific on how and where your paths are to be used. For instance os.chdir() will work fine with a mixture, but command line apps or native APIs will probably fail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmueller at python-academy.de Thu Feb 3 19:01:35 2011 From: mmueller at python-academy.de (=?ISO-8859-15?Q?Mike_M=FCller?=) Date: Fri, 04 Feb 2011 01:01:35 +0100 Subject: 8-Day Python Power Course in Leipzig/Germany Message-ID: <4D4B41DF.8070605@python-academy.de> Eight Days of Python Training ----------------------------- Can't get enough of Python? Then this course is for you. A three day introduction to Python as a warm-up, followed by five days of advanced Python training. All courses given in English. May 13 - 15, 2011 Python for Programmers May 16 - 20, 2011 Python Power Course May 16, 2011 Advanced Python Programming May 17, 2011 Optimizing Python Programs May 18, 2011 Python Extensions with Other Languages May 19, 2011 Fast Code with the Cython Compiler May 20, 2011 High Performance XML with Python Venue: Python Academy, Leipzig, Germany Trainers: Mike M?ller, Stefan Behnel About the Trainers ------------------ Mike M?ller, Ph.D has been teaching Python since 2004. He is the founder of Python Academy and regularly gives open and in-house Python courses as well as tutorials at PyCon US, OSCON, EuroSciPy and PyCon Asia-Pacific. Stefan Behnel, Ph.D is Senior Software Developer at Senacor Technologies AG as well as freelance consultant and software developer specializing in Python and Open Source. He is core developer of both the Cython compiler and the lxml XML toolkit. More Information ---------------- http://www.python-academy.com/courses/python_power_course.html -- Mike mmueller at python-academy.de From anikom15 at gmail.com Thu Feb 3 19:10:19 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 03 Feb 2011 16:10:19 -0800 Subject: os.path.join doubt In-Reply-To: <3F.53.14011.4F04B4D4@hrndva-omtalb.mail.rr.com> References: <557716be-962d-44af-924d-effc0b247cbb@x11g2000yqc.googlegroups.com> <4d4a4bd5$0$29973$c3e8da3$5496439d@news.astraweb.com> <4d4b360c$0$30000$c3e8da3$5496439d@news.astraweb.com> <1296776014.22034.4.camel@localhost.localdomain> <3F.53.14011.4F04B4D4@hrndva-omtalb.mail.rr.com> Message-ID: <1296778219.22034.7.camel@localhost.localdomain> On Thu, 2011-02-03 at 17:57 -0600, Thomas L. Shinnick wrote: > At 05:33 PM 2/3/2011, Westley Mart?nez wrote: > > > On Thu, 2011-02-03 at 23:11 +0000, Steven D'Aprano wrote: > > > > > On Thu, 03 Feb 2011 > > > 07:58:55 -0800, Ethan Furman wrote: > > > > Steven D'Aprano wrote: > > > [snip] > > > > > > Yes. Is there a problem? All those paths should be usable from Windows. > > > If you find it ugly to see paths with a mix of backslashes and forward > > > slashes, call os.path.normpath, or just do a simple string replace: > > > > > > path = path.replace('/', '\\') > > > > > > before displaying them to the user. Likewise if you have to pass the > > > paths to some application that doesn't understand slashes. > > > > > > > > > -- > > > Steven > > > > Paths that mix /s and \s are NOT valid on Windows. In one of the > > setup.py scripts I wrote I had to write a function to collect the > > paths of data files for installation. On Windows it didn't work and > > it was driving me crazy. It wasn't until I realized os.path.join was > > joining the paths with \\ instead of / that I was able to fix it. > > > > def find_package_data(path): > > """Recursively collect EVERY file in path to a list.""" > > oldcwd = os.getcwd() > > os.chdir(path) > > filelist = [] > > for path, dirs, filenames in os.walk('.'): > > for name in filenames: > > filename = ((os.path.join(path, name)).replace('\\', > > '/')) > > filelist.append(filename.replace('./', 'data/')) > > os.chdir(oldcwd) > > return filelist > > > Please check out os.path.normpath() as suggested. Example: > >>> import os > >>> s = r"/hello\\there//yall\\foo.bar" > >>> s > '/hello\\\\there//yall\\\\foo.bar' > >>> v = os.path.normpath(s) > >>> v > '\\hello\\there\\yall\\foo.bar' > > The idea behind os.path is to cater to the host OS. Thus > os.path.normpath() will convert to the host's acceptable delimiters. > That is, you didn't need the .replace(), but rather to more fully use > the existing library to good advantage with .normpath(). > > However, note that delimiters becomes an issue only when directly > accessing the host OS, such as when preparing command line calls or > accessing native APIs. Within the Python library/environment, both > '/' and '\' are acceptable. External use is a different matter. > > So, you need to be specific on how and where your paths are to be > used. For instance os.chdir() will work fine with a mixture, but > command line apps or native APIs will probably fail. The reason why I use replace instead of normpath is because I want it to '/'s on ALL platforms. This is because distutils requires the use of '/'s. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwayneblind at gmail.com Thu Feb 3 19:25:36 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Fri, 4 Feb 2011 01:25:36 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> <4D4AF98D.1060706@ixokai.io> Message-ID: or rather timeout = s.gettimeout() b=time.clock() while time.clock()-b<3 : s.settimeout(3-time.clock()+b) try : data=s.recv(1024) except : break s.settimeout(timeout) Sorry for all these messages Dwayne 2011/2/4 Dwayne Blind > The solution would be > > > timeout = s.gettimeout() > s.settimeout(3) > b=time.clock() > while time.clock()-b<3 : > try : > data=s.recv(1024) > except : > break > s.settimeout(timeout) > > Am I right ? > > Dwayne > > 2011/2/4 Dwayne Blind > > Thanks Stephen. It's really nice of you. >> >> I have not understood everything though. (I have never used a context >> manager before.) >> >> Here are some comments : >> >> timeout = s.gettimeout() # Is that the default timeout ? >> s.settimeout(3) # I guess this is a 3 second timeout >> s.recv(1024) >> s.settimeout(timeout) # You change it back ? >> >> So with a while loop, it should be : >> >> >> timeout = s.gettimeout() >> s.settimeout(3) >> b=time.clock() >> while time.clock()-b<3 : >> >> data=s.recv(1024) >> s.settimeout(timeout) >> >> Am I right ? >> >> Thanks again, >> Dwayne >> >> >> 2011/2/3 Stephen Hansen >> >>> On 2/3/11 10:13 AM, Dwayne Blind wrote: >>> >>> > Thanks for your answer. I don't want to reset my socket. I want to >>> apply >>> > the timeout to the rcv method only. >>> >>> Setting the timeout does not "reset [your] socket", I don't think. And I >>> get that you want to only timeout recv... that's why I pointed out its a >>> socket method, not an argument to recv. If you don't want it to apply to >>> everything else, you just have to be sure to change it back after recv. >>> >>> Just: >>> timeout = s.gettimeout() >>> s.settimeout(3) >>> s.recv(1024) >>> s.settimeout(timeout) >>> >>> Personally, I'd prefer to do: >>> >>> with timeout(s, 3): >>> s.recv(1024) >>> >>> That's a lot more clear, and I'd roll this context manager to accomplish >>> it: >>> >>> --- start >>> >>> from contextlib import contextmanager >>> >>> @contextmanager >>> def timeout(sock, timeout): >>> old_timeout = sock.gettimeout() >>> sock.settimeout(timeout) >>> try: >>> yield sock >>> finally: >>> sock.settimeout(old_timeout) >>> >>> --- end >>> >>> The contextmanager decorator is an easy/quick way of making a context >>> manager. Everything up until the yield is executed before the 'with' >>> block is run, and everything after the yield is executed after the >>> 'with' block concludes. >>> >>> If the with block throws an exception, it'll be catchable at the yield >>> point. >>> >>> -- >>> >>> Stephen Hansen >>> ... Also: Ixokai >>> ... Mail: me+list/python (AT) ixokai (DOT) io >>> ... Blog: http://meh.ixokai.io/ >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Thu Feb 3 20:29:39 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Thu, 03 Feb 2011 17:29:39 -0800 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> <4D4AF98D.1060706@ixokai.io> Message-ID: <4D4B5683.90900@ixokai.io> On 2/3/11 3:02 PM, Dwayne Blind wrote: > Thanks Stephen. It's really nice of you. > > I have not understood everything though. (I have never used a context > manager before.) > > Here are some comments : > > timeout = s.gettimeout() # Is that the default timeout ? > s.settimeout(3) # I guess this is a 3 second timeout > s.recv(1024) > s.settimeout(timeout) # You change it back ? Yes. > So with a while loop, it should be : I don't understand why you're doing this while loop business. Your original question is asking for how to NOT do that, I thought. How to use a timeout instead. I showed you how to use a timeout instead-- now you're mixing it in with what you originally had? Why? -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From kushal.kumaran+python at gmail.com Thu Feb 3 20:52:02 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 4 Feb 2011 07:22:02 +0530 Subject: Download an attachment from an IMAP email In-Reply-To: References: Message-ID: On Fri, Feb 4, 2011 at 3:44 AM, Vincent Davis wrote: > I have a few emails I am trying to download from my google account. I seem > to be getting the message but each of these messages have an attachment. I > don't understand what I ned to do to get and save the attachment to a local > file. > Here is what I have so far. > M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT) > rc, resp = M.login('xxxxx at xxxx', 'XXXXX') > print rc, resp > M.select('[Gmail]/All Mail') > M.search(None, 'FROM', 'someone at logitech.com') > #M.fetch(121, '(body[header.fields (subject)])') > M.fetch(121, '(RFC822)') Take a look at the email module. The message_from_string() function can convert the string representation of the email (as obtained by M.fetch(121, '(RFC822)') into a message object. -- regards, kushal From mdekauwe at gmail.com Thu Feb 3 21:43:22 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Thu, 3 Feb 2011 18:43:22 -0800 (PST) Subject: code structure advise for a model Message-ID: Hi, I am translating some c++ code to python and just wanted to ask some advise on structure. The original has everything declared globally and nothing passed via function (I assume, but don't know, that this isn't just standard c++ practice!). So given this, I have a pretty much clean slate as I can't quite just copy the functions over. I was thinking something like this class Params: def __init__(self, fname): self.set_inital_condtions() self.read_input_file(fname) def set_inital_conditons(self): self.some_parm = 0.0 def read_input_file(fname): #read file, change initial params if specified then I thought I could pass this as an object to the model class class Model(Params): def __init__(self): # blah def some_func(self): if (Params.some_param == something): foo OR this just a very bad way to structure it? The other thing I can't decide on is how to pass the parameters and variables through the class. So because of the way the original is written (everything is global), I could just inherit things, but it does means there is a lot of self. syntax. So I wondered if it might be better to pass things as function arguments? Any thoughts? I am also half considering other users from non-python backgrounds and what might seem very alien (syntax) to them. thanks in advance (ps. I am cross posting this on comp.lang.python as I am not sure where is more appropriate). From davea at ieee.org Fri Feb 4 01:10:18 2011 From: davea at ieee.org (Dave Angel) Date: Fri, 04 Feb 2011 01:10:18 -0500 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> <4D4AF98D.1060706@ixokai.io> Message-ID: <4D4B984A.2050006@ieee.org> On 01/-10/-28163 02:59 PM, Dwayne Blind wrote: > or rather > > timeout = s.gettimeout() > b=time.clock() > while time.clock()-b<3 : > s.settimeout(3-time.clock()+b) > try : > data=s.recv(1024) > except : > break > s.settimeout(timeout) > > Sorry for all these messages > > Dwayne > You accidentally top-posted, so I had to delete all the history. Without knowing anything about "s", there are two problems with this logic: 1) if you loop through the while more than once, you'll be throwing out old data. So you might need something like data += s.recv(1024). Conversely, if an exception happens, data is completely undefined. Without defining a default value, your remaining code is likely to get an exception. 2) Your time spent might vary between 3 and 6 seconds. If you need a tighter control than that, play with the timeout a little. For example, you might want a 1/2 second timeout, and loop until the total is 3 seconds. That way the tolerance will be 3 to 3.5 seconds. Bonus: I don't know the behavior of the object, so I don't know what state it's in after you timeout. DaveA -- -- davea at ieee.org From nawijn at gmail.com Fri Feb 4 04:41:55 2011 From: nawijn at gmail.com (Marco Nawijn) Date: Fri, 4 Feb 2011 01:41:55 -0800 (PST) Subject: code structure advise for a model References: Message-ID: <314af16f-adf2-4d78-88a8-2cb50843d858@a28g2000vbo.googlegroups.com> On Feb 4, 3:43?am, Martin De Kauwe wrote: > Hi, > > I am translating some c++ code to python and just wanted to ask some > advise on structure. The original has everything declared globally and > nothing passed via function (I assume, but don't know, that this isn't > just standard c++ practice!). So given this, I have a pretty much > clean slate as I can't quite just copy the functions over. I was > thinking something like this > > class Params: > > ? ? def __init__(self, fname): > ? ? ? ? self.set_inital_condtions() > ? ? ? ? self.read_input_file(fname) > > ? ? def set_inital_conditons(self): > ? ? ? ? self.some_parm = 0.0 > > ? ? def read_input_file(fname): > > ? ? ? ? #read file, change initial params if specified > > then I thought I could pass this as an object to the model class > > class Model(Params): > > ? ? def __init__(self): > ? ? ? ? # blah > > ? ? def some_func(self): > ? ? ? ? ?if (Params.some_param == something): > ? ? ? ? ? ? ?foo > > OR this just a very bad way to structure it? > > The other thing I can't decide on is how to pass the parameters and > variables through the class. So because of the way the original is > written (everything is global), I could just inherit things, but it > does means there is a lot of self. syntax. So I wondered if it might > be better to pass things as function arguments? Any thoughts? I am > also half considering other users from non-python backgrounds and what > might seem very alien (syntax) to them. > > thanks in advance > > (ps. I am cross posting this on comp.lang.python as I am not sure > where is more appropriate). I would structure it in three classes/functions: 1. A parser class/function that reads an input file and returns a Parameters object 2. A Parameters class 3. A Model class that uses the Parameters You would end up with something like the following: class MyParser(object): def __init__(self, filename=None): self.filename = filename def parse(self, filename): params = Parameters() ...read info from filename and update parameters return params class Parameters(object): def __init__(self): self.myAttribute1 = 0 self.myAttribute2 = "A string" class MyModel(object): def __init__(self, parameters): self.parameters = parameters def solve(self): ...solve the problem The driver program would look something like this: parser = MyParser() params = parser.parse('inputfile') model = MyModel(params) model.solve() I hope this is helpfull for you. Regards, Marco From flebber.crue at gmail.com Fri Feb 4 04:55:48 2011 From: flebber.crue at gmail.com (flebber) Date: Fri, 4 Feb 2011 01:55:48 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> Message-ID: <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> On Feb 3, 7:41?am, Corey Richardson wrote: > On 2/2/2011 2:44 PM, rantingrick wrote: > > Will you be forking IDLE and setting up some sort of tracker for > improvements? +1 for this. Enough talk ratingrick where is your feature and request tracker for your idle fork? How can people assist you in your new idle fork project? What are your stated project goals & timeline? We all suspect you have no answers to basic questions which would involve you doing anything!!! So come on rick reply with some other pius full of shit answer that will absolve you of action and will still leave you the worlds biggest one handed typist. From __peter__ at web.de Fri Feb 4 05:12:47 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 04 Feb 2011 11:12:47 +0100 Subject: code structure advise for a model References: Message-ID: Martin De Kauwe wrote: > I am translating some c++ code to python and just wanted to ask some > advise on structure. The original has everything declared globally and > nothing passed via function (I assume, but don't know, that this isn't > just standard c++ practice!). So given this, I have a pretty much > clean slate as I can't quite just copy the functions over. I was > thinking something like this > > class Params: > > def __init__(self, fname): > self.set_inital_condtions() > self.read_input_file(fname) > > def set_inital_conditons(self): > self.some_parm = 0.0 > > > def read_input_file(fname): > > #read file, change initial params if specified > > > then I thought I could pass this as an object to the model class > > class Model(Params): > > def __init__(self): > # blah > > def some_func(self): > if (Params.some_param == something): > foo > > OR this just a very bad way to structure it? Your question is too low-level, and too technical. If you give a short description of what the program does and what options you see to structure it *in* *plain* *english* you'll get a clearer picture yourself and better answers. In general use functions, and switch to classes only if you can demonstrate that they make the program's structure easier to understand. Rather than use inheritance to split a "big beast that does it all" into smaller chunks aggregate smaller classes. > The other thing I can't decide on is how to pass the parameters and > variables through the class. So because of the way the original is > written (everything is global), I could just inherit things, but it > does means there is a lot of self. syntax. So I wondered if it might > be better to pass things as function arguments? Any thoughts? I am > also half considering other users from non-python backgrounds and what > might seem very alien (syntax) to them. Yes, passing data to functions/methods/classes explicitly is better than global state and also preferable over instance state. From jeanmichel at sequans.com Fri Feb 4 05:52:06 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 04 Feb 2011 11:52:06 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: <4D4AEE18.5050301@ixokai.io> References: <4D4AEE18.5050301@ixokai.io> Message-ID: <4D4BDA56.3040502@sequans.com> Stephen Hansen wrote: > On 2/3/11 9:56 AM, Dwayne Blind wrote: > >> However I would like to set timeout on the socket rcv method, so that >> the while loop stops exactly after 3 seconds. Is this possible ? >> > > I rarely do low-level socket stuff -- [snip] > > Good point. Python has a module for almost anything you would need to do on a network. Make sure none of these modules fit your needs. You could tell us what you want to achieve at a higher level, we may point you to a already existing module. Some of these modules are life saver, as I personnally always wrote buggy netcode for whatever reason :( JM From V.vanBeveren at rijnhuizen.nl Fri Feb 4 07:39:33 2011 From: V.vanBeveren at rijnhuizen.nl (Vincent van Beveren) Date: Fri, 4 Feb 2011 13:39:33 +0100 Subject: Deadlock and a rather weird stacktrace Message-ID: <2926F4BC94217A43A2D21792DE881893479E86A02A@ex1.rijnh.nl> Hi everyone, I'm currently working on a multithreaded GUI system in Python 2.6. In this system I use conditions to coordinate synchronization. However, one condition suddenly locks, without any cause. As a last resort I have written a small routine to dump all the stack traces. def dumpAllStacks(self): for threadId, stack in sys._current_frames().items(): print "Thread with Id: %s" % threadId traceback.print_stack(stack) When the system is dead-locked, I invoke this method. One stack-trace strikes me as odd: Thread with Id: 1568 File "c:\PYTHON26\lib\threading.py", line 497, in __bootstrap self.__bootstrap_inner() File "c:\PYTHON26\lib\threading.py", line 525, in __bootstrap_inner self.run() File "c:\PYTHON26\lib\threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "c:\PYTHON26\lib\site-packages\magnum\gui\autogui.py", line 2558, in __sendDataLoop self.__sendDataCondition.wait(1) File "c:\PYTHON26\lib\threading.py", line 256, in wait _sleep(delay) File "c:\PYTHON26\lib\threading.py", line 497, in __bootstrap self.__bootstrap_inner() <<===== What? File "c:\PYTHON26\lib\threading.py", line 525, in __bootstrap_inner self.run() File "c:\PYTHON26\lib\site-packages\magnum\subsys\__init__.py", line 2242, in run self.updateTask() File "c:\PYTHON26\lib\site-packages\magnum\subsys\__init__.py", line 2214, in updateTask self.statusServerModule.updateTaskWithConnection(self.statusServerConnection) File "c:\PYTHON26\lib\site-packages\magnum\subsys\shared\modules.py", line 2450, in updateTaskWithConnection self.updateDataWithConnection(connection, updateAll) File "c:\PYTHON26\lib\site-packages\magnum\subsys\shared\modules.py", line 2488, in updateDataWithConnection self.updateVariableData(varDataDict, frozenset(varDataDict)) File "c:\PYTHON26\lib\site-packages\magnum\subsys\shared\modules.py", line 796, in updateVariableData self.cmdMgr.updateVariableData(self.moduleId, varDataDict, forceVarIdSet) # after this varMgr makes deepcopy File "c:\PYTHON26\lib\site-packages\magnum\subsys\shared\managers.py", line 441, in updateVariableData self.notifyUpdateReport(updatedData) File "c:\PYTHON26\lib\site-packages\magnum\subsys\shared\managers.py", line 493, in notifyUpdateReport with self.updateReportCondition: File "c:\PYTHON26\lib\threading.py", line 205, in __enter__ return self.__lock.__enter__() File "c:\PYTHON26\lib\threading.py", line 121, in acquire rc = self.__block.acquire(blocking) Can someone tell me how the sleep of one thread can continue as the 'run' of another? Is this normal? Thanks in advance! Regards, Vincent van Beveren ___ Ing. V. van Beveren Software Engineer,?FOM Rijnhuizen T: +31 (0) 30-6096769 E: V.vanBeveren at rijnhuizen.nl From gelonida at gmail.com Fri Feb 4 08:35:58 2011 From: gelonida at gmail.com (gelonida) Date: Fri, 4 Feb 2011 05:35:58 -0800 (PST) Subject: How to debug a problem with python crashing under windows Message-ID: <334b65cd-fd44-4aa0-9798-8399e786beb7@w36g2000vbi.googlegroups.com> Hi, I have a python application, which occasionally crashes. With crashing I mean, that windows pops up a screen saying, that python.exe failed. I do not have any usable trace on stdout / stderr. What are the best means to analyze such errors? Is there any way to get something like a core dump and to look at it after the application died? Thanks in advance for any idea. From dwayneblind at gmail.com Fri Feb 4 09:55:33 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Fri, 4 Feb 2011 15:55:33 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: <4D4BDA56.3040502@sequans.com> References: <4D4AEE18.5050301@ixokai.io> <4D4BDA56.3040502@sequans.com> Message-ID: Thanks to all of you. @ Jean-Michel Pichavant I am writing a small multiplayer game. Several clients are connected to the server. Games last, say, 20 seconds. You can think of the game as a small chat lasting 20 seconds. All the data received by the server is sent back to the clients. @ Stephen Hansen Each player can send as many words as he wants. I think this is why I need the loop. Don't you think so ? @ Dave Angel s = conn, with conn,address=socket.accept() (see Socket Objects) Thanks again 2011/2/4 Jean-Michel Pichavant > Stephen Hansen wrote: > >> On 2/3/11 9:56 AM, Dwayne Blind wrote: >> >> >>> However I would like to set timeout on the socket rcv method, so that >>> the while loop stops exactly after 3 seconds. Is this possible ? >>> >>> >> >> I rarely do low-level socket stuff -- [snip] >> >> >> > Good point. Python has a module for almost anything you would need to do on > a network. Make sure none of these modules fit your needs. > You could tell us what you want to achieve at a higher level, we may point > you to a already existing module. > > Some of these modules are life saver, as I personnally always wrote buggy > netcode for whatever reason :( > > JM > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 4 10:31:15 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 04 Feb 2011 16:31:15 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> <4D4BDA56.3040502@sequans.com> Message-ID: <4D4C1BC3.1040403@sequans.com> Dwayne Blind wrote: > Thanks to all of you. > > @ Jean-Michel Pichavant > I am writing a small multiplayer game. Several clients are connected > to the server. Games last, say, 20 seconds. > You can think of the game as a small chat lasting 20 seconds. All the > data received by the server is sent back to the clients. > > @ Stephen Hansen > Each player can send as many words as he wants. I think this is why I > need the loop. Don't you think so ? > > @ Dave Angel > s = conn, with conn,address=socket.accept() > (see Socket Objects) > > Thanks again Please do not Top post :) xmlrpclib and Pyro are for example 2 modules that could have taken care of your netcode. In your case, Pyro could be perfect for you since it has no constraint (basically the xmlrpc protocol). Quoting Pyro's home page: "Never worry about writing network communication code again, when using Pyro you just write your Python objects like you would normally. With only a few lines of extra code, Pyro takes care of the network communication between your objects once you split them over different machines on the network. All the gory socket programming details are taken care of, you just call a method on a remote object as if it were a local object!". See the examples to get better idea of remote calls with pyro. JM From research at johnohagan.com Fri Feb 4 10:48:55 2011 From: research at johnohagan.com (John O'Hagan) Date: Fri, 4 Feb 2011 15:48:55 +0000 Subject: Reassign or discard Popen().stdout from a server process In-Reply-To: References: Message-ID: <201102041548.56427.research@johnohagan.com> On Thu, 3 Feb 2011, Nobody wrote: > On Tue, 01 Feb 2011 08:30:19 +0000, John O'Hagan wrote: > > I can't keep reading because that will block - there won't be any more > > output until I send some input, and I don't want it in any case. > > > > To try to fix this I added: > > > > proc.stdout = os.path.devnull > > > > which has the effect of stopping the server from failing, but I'm not > > convinced it's doing what I think it is. > > It isn't. os.path.devnull is a string, not a file. But even if you did: > > proc.stdout = open(os.path.devnull, 'w') > > that still wouldn't work. As mentioned earlier in the thread, I did in fact use open(), this was a typo, [...] > > Is it possible to re-assign the stdout of a subprocess after it has > > started? > > No. > > > Or just close it? What's the right way to read stdout up to a given > > line, then discard the rest? > > If the server can handle the pipe being closed, go with that. Otherwise, > options include redirecting stdout to a file and running "tail -f" on the > file from within Python, or starting a thread or process whose sole > function is to read and discard the server's output. Thanks, that's all clear now. But I'm still a little curious as to why even unsuccessfully attempting to reassign stdout seems to stop the pipe buffer from filling up. John From old_road_farm at verizon.net Fri Feb 4 11:24:41 2011 From: old_road_farm at verizon.net (octopusgrabbus) Date: Fri, 4 Feb 2011 08:24:41 -0800 (PST) Subject: Re-installing 2.6.6 to build shared library Message-ID: In order to accommodate a mod_wsgi build problem, I need to have a Python shared library. What is the best way to re-install Python to do this? Many thanks. cmn From rustompmody at gmail.com Fri Feb 4 11:34:16 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 4 Feb 2011 08:34:16 -0800 (PST) Subject: Use the Source Luke References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> Message-ID: On Feb 2, 12:32?am, "OKB (not okblacke)" wrote: > Tim Wintle wrote: > > (2) is especially important IMO - under half of the python > > developers I have regularly worked with would feel comfortable > > reading C - so for the other half reading C source code probably > > isn't going to help them understand exactly what's going on > > (although in the long run it might help them a lot) > > ? ? ? ? I'd just like to note that (2) applies to me in spades. ?I'm not > sure how many other people are in my position, but I use Python because > I like how it works, and I do not want to use C because I find it > insufferable. ?I quite frequently look at the source of Python modules, > although more often third-party modules than the standard lib, but if I > have to look at the C source of something I basically stop and find > another solution (possibly abandoning Python altogether for that usage). > > ? ? ? ? I think, in general, the less anyone needs to know C even exists, > the better for Python; likewise, the more that people have to mention > the existence of C in a Python context, the worse for Python. ?This may > be a somewhat extreme viewpoint, but that's my position. In 1990 I wrote a paper elaborating this. http://portal.acm.org/citation.cfm?id=126471 It is dated (before python, java, haskell and the internet as we know it today) It is also dated in the sense that I dont totally agree with the strong views therein (I was half my age then :-) Still if you want it its here https://docs.google.com/document/d/1P-BQtpyzjjjOKxzhKjIGI-GLMXW5bOZ6xYBJhApwqLc/edit?hl=en [PS Does not read properly in google docs though it reads ok in acroread and evince ] From wanderer at dialup4less.com Fri Feb 4 11:39:54 2011 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 4 Feb 2011 08:39:54 -0800 (PST) Subject: Converging Multiple Classes Message-ID: <00bd4240-6aae-4071-a6eb-b765861af18d@y31g2000prd.googlegroups.com> I have a bunch of cameras I want to run tests on. They each have different drivers and interfaces. What I want to do is create python wrappers so that they all have a common interface and can be called by the same python test bench program. I'm not sure what to call it. I don't think it's inheritance. Maybe there is no official thing here and I just need to brute force my way through it. Is there some programming methodology I should be using? Thanks From miki.tebeka at gmail.com Fri Feb 4 11:41:59 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 4 Feb 2011 08:41:59 -0800 (PST) Subject: How to debug a problem with python crashing under windows In-Reply-To: <334b65cd-fd44-4aa0-9798-8399e786beb7@w36g2000vbi.googlegroups.com> Message-ID: <2ccb4afa-dcdb-4cbf-8d02-247c3e468c02@glegroupsg2000goo.googlegroups.com> > With crashing I mean, that windows pops up a screen saying, that > python.exe failed. > I do not have any usable trace on stdout / stderr. > > What are the best means to analyze such errors? You can use sys.excepthook to catch uncaught exceptions. See http://pythonwise.blogspot.com/2008/12/crashlog.html for example ;) HTH, -- Miki From georger.silva at gmail.com Fri Feb 4 11:54:20 2011 From: georger.silva at gmail.com (George Silva) Date: Fri, 4 Feb 2011 14:54:20 -0200 Subject: Converging Multiple Classes In-Reply-To: <00bd4240-6aae-4071-a6eb-b765861af18d@y31g2000prd.googlegroups.com> References: <00bd4240-6aae-4071-a6eb-b765861af18d@y31g2000prd.googlegroups.com> Message-ID: Take a look at the strategy pattern. But with python being a dinamic language, you probably won't need to implement it like that. http://en.wikipedia.org/wiki/Strategy_pattern Example: # import all you need CAMERAS = ['A','B','C'] def capture_A: pass def capture_B: pass def capture_C: pass def capture(camera): if camera in CAMERAS: if camera = 'A': function = capture_A if camera = 'B': function = capture_B if camera = 'C': function = capture_C # call function function() else return On Fri, Feb 4, 2011 at 2:39 PM, Wanderer wrote: > I have a bunch of cameras I want to run tests on. They each have > different drivers and interfaces. What I want to do is create python > wrappers so that they all have a common interface and can be called by > the same python test bench program. I'm not sure what to call it. I > don't think it's inheritance. Maybe there is no official thing here > and I just need to brute force my way through it. Is there some > programming methodology I should be using? > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > -- George R. C. Silva Desenvolvimento em GIS http://blog.geoprocessamento.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Fri Feb 4 11:56:20 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 04 Feb 2011 08:56:20 -0800 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> <4D4BDA56.3040502@sequans.com> Message-ID: <4D4C2FB4.2070503@ixokai.io> On 2/4/11 6:55 AM, Dwayne Blind wrote: > @ Jean-Michel Pichavant > I am writing a small multiplayer game. Several clients are connected to > the server. Games last, say, 20 seconds. > You can think of the game as a small chat lasting 20 seconds. All the > data received by the server is sent back to the clients. > > @ Stephen Hansen > Each player can send as many words as he wants. I think this is why I > need the loop. Don't you think so ? No. I've never seen or used network code which operated in any way like that. Sometimes you want code which blocks, sometimes you want code that doesn't: sometimes you want stuff that may block for a little while, but with a timeout. I can't even imagine why you'd want code which aggressively tries to read for multiple seconds before moving on. Either the read works and you have data; or it doesn't, and you move on to do something else and try again later. Perhaps after trying to read from another socket-- or, perhaps after a select.select() call tells you there's something more to read. T But you need to separate the logic of your game from this network infrastructure. From your game logic perspective, perhaps you process the responses line by line. From your network logic perspective, you may happen to get one character at a time-- or it may burst to you all at once. The socket interfaces will try to give you up to the requested number of bytes but the network layer has every possibility of just giving you partial responses. So the network layer should just gather up the data as it arrives, buffer it -- and pass it off to the game logic layer as each line is complete (i.e., as \r\n or \n's are received). But there's no reason at all to do a while loop to aggressively try to read from one particular socket repeatedly for multiple seconds. At least, none that I've ever run into. Granted, I'm not at all a master of socket-fu. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rustompmody at gmail.com Fri Feb 4 11:58:55 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 4 Feb 2011 08:58:55 -0800 (PST) Subject: Use the Source Luke References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> Message-ID: <33dc764a-1fbe-478a-ba9f-613d4883e728@z3g2000prz.googlegroups.com> On Feb 4, 9:34?pm, rusi wrote: > > [PS Does not read properly in google docs though it reads ok in > acroread and evince ] Sorry google docs does not like the pdf Heres a ps https://docs.google.com/leaf?id=0B3gsacOF56PxOWUxZTVmOTQtYWIxNy00ZGFjLWEwODUtZDVkM2MyZGI5ZmRk&hl=en From srikrishnamohan at gmail.com Fri Feb 4 12:06:15 2011 From: srikrishnamohan at gmail.com (km) Date: Fri, 4 Feb 2011 22:36:15 +0530 Subject: shared python module ? Message-ID: Hi all, I have two version of python 2.6 and 2.7. Now Is there any way that I install a python module (from pypi) and import it across both the versions ? regards, KM -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 4 12:07:39 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 04 Feb 2011 18:07:39 +0100 Subject: Converging Multiple Classes In-Reply-To: <00bd4240-6aae-4071-a6eb-b765861af18d@y31g2000prd.googlegroups.com> References: <00bd4240-6aae-4071-a6eb-b765861af18d@y31g2000prd.googlegroups.com> Message-ID: <4D4C325B.2000105@sequans.com> Wanderer wrote: > I have a bunch of cameras I want to run tests on. They each have > different drivers and interfaces. What I want to do is create python > wrappers so that they all have a common interface and can be called by > the same python test bench program. I'm not sure what to call it. I > don't think it's inheritance. Maybe there is no official thing here > and I just need to brute force my way through it. Is there some > programming methodology I should be using? > > Thanks > I guess Interface/Abstract classes are what you are searching for. # Camera is the interface/abstract base class of all cameras. # it defines all the function that a Camera needs to implement. class Camera(object): def printCameraType(self): # This code is common to all Cameras print self.__class__.__name__ def shutdown(self): # an abstract method raises NotImplementedError and does not implement anything # however it indicates to all child classes what they need to implement. raise NotImplementedError() # One implementation of a Camera class ATypeOfCamera(Camera): def shutdown(): print 'I am implementing the shutdown for that very specific Camera type' return 0 class AnotherTypeOfCamera(Camera): def shutdown(): print 'Shutting down with the proper implementation' return 0 Now here is what you test bench whould look like: from camera import ATypeOfCamera, AnotherTypeOfCamera for cameraType in [ATypeOfCamera, AnotherTypeOfCamera]: myCam = cameraType() myCam.printCameraType() myCam.shutdown() JM From wanderer at dialup4less.com Fri Feb 4 12:12:35 2011 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 4 Feb 2011 09:12:35 -0800 (PST) Subject: Converging Multiple Classes References: <00bd4240-6aae-4071-a6eb-b765861af18d@y31g2000prd.googlegroups.com> Message-ID: <8a7fd5bc-a992-468e-9e13-dfa8196f8e74@i39g2000prd.googlegroups.com> On Feb 4, 12:07?pm, Jean-Michel Pichavant wrote: > Wanderer wrote: > > I have a bunch of cameras I want to run tests on. They each have > > different drivers and interfaces. What I want to do is create python > > wrappers so that they all have a common interface and can be called by > > the same python test bench program. I'm not sure what to call it. I > > don't think it's inheritance. Maybe there is no official thing here > > and I just need to brute force my way through it. Is there some > > programming methodology I should be using? > > > Thanks > > I guess Interface/Abstract classes are what you are searching for. > > # Camera is the interface/abstract base class of all cameras. > # it defines all the function that a Camera needs to implement. > class Camera(object): > ? ? def printCameraType(self): > ? ? ? ?# This code is common to all Cameras > ? ? ? ?print self.__class__.__name__ > > ? ? def shutdown(self): > ? ? ? ?# an abstract method raises NotImplementedError and does not > implement anything > ? ? ? ?# however it indicates to all child classes what they need to > implement. > ? ? ? ?raise NotImplementedError() > > # One implementation of a Camera > class ATypeOfCamera(Camera): > ? ? def shutdown(): > ? ? ? ?print 'I am implementing the shutdown for that very specific > Camera type' > ? ? ? ?return 0 > > class AnotherTypeOfCamera(Camera): > ? ? def shutdown(): > ? ? ? ?print 'Shutting down with the proper implementation' > ? ? ? ?return 0 > > Now here is what you test bench whould look like: > > from camera import ATypeOfCamera, AnotherTypeOfCamera > > for cameraType in [ATypeOfCamera, AnotherTypeOfCamera]: > ? ? myCam = cameraType() > ? ? myCam.printCameraType() > ? ? myCam.shutdown() > > JM Thanks JM. That help a lot. From dwayneblind at gmail.com Fri Feb 4 12:16:38 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Fri, 4 Feb 2011 18:16:38 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: <4D4C2FB4.2070503@ixokai.io> References: <4D4AEE18.5050301@ixokai.io> <4D4BDA56.3040502@sequans.com> <4D4C2FB4.2070503@ixokai.io> Message-ID: Thank you very much Jean-Michel Pichavant and Stephen Hansen. @ Jean-Michel Pichavant I will have a look at Pyro. @ Stephen Hansen Now I am pretty much worried. :'( 2011/2/4 Stephen Hansen > On 2/4/11 6:55 AM, Dwayne Blind wrote: > > @ Jean-Michel Pichavant > > I am writing a small multiplayer game. Several clients are connected to > > the server. Games last, say, 20 seconds. > > You can think of the game as a small chat lasting 20 seconds. All the > > data received by the server is sent back to the clients. > > > > @ Stephen Hansen > > Each player can send as many words as he wants. I think this is why I > > need the loop. Don't you think so ? > > No. I've never seen or used network code which operated in any way like > that. Sometimes you want code which blocks, sometimes you want code that > doesn't: sometimes you want stuff that may block for a little while, but > with a timeout. > > I can't even imagine why you'd want code which aggressively tries to > read for multiple seconds before moving on. > > Either the read works and you have data; or it doesn't, and you move on > to do something else and try again later. Perhaps after trying to read > from another socket-- or, perhaps after a select.select() call tells you > there's something more to read. T > > But you need to separate the logic of your game from this network > infrastructure. > > From your game logic perspective, perhaps you process the responses line > by line. From your network logic perspective, you may happen to get one > character at a time-- or it may burst to you all at once. The socket > interfaces will try to give you up to the requested number of bytes but > the network layer has every possibility of just giving you partial > responses. > > So the network layer should just gather up the data as it arrives, > buffer it -- and pass it off to the game logic layer as each line is > complete (i.e., as \r\n or \n's are received). But there's no reason at > all to do a while loop to aggressively try to read from one particular > socket repeatedly for multiple seconds. At least, none that I've ever > run into. > > Granted, I'm not at all a master of socket-fu. > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From me+list/python at ixokai.io Fri Feb 4 12:30:17 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 04 Feb 2011 09:30:17 -0800 Subject: socket.rcv timeout while-loop In-Reply-To: References: <4D4AEE18.5050301@ixokai.io> <4D4BDA56.3040502@sequans.com> <4D4C2FB4.2070503@ixokai.io> Message-ID: <4D4C37A9.5060601@ixokai.io> On 2/4/11 9:16 AM, Dwayne Blind wrote: > @ Stephen Hansen > Now I am pretty much worried. :'( Why? This is all sounding like a problem that isn't actually a problem. I think you may have over-analyzed yourself into a corner and think you have something to solve which doesn't really need solving. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rantingrick at gmail.com Fri Feb 4 13:25:42 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 4 Feb 2011 10:25:42 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <30c1a682-f26c-43fe-9e13-ef8e8556dc92@i14g2000prm.googlegroups.com> <68ea4e91-a79b-4fa9-9488-599bab595242@r16g2000yqk.googlegroups.com> Message-ID: On Feb 3, 11:15?am, rantingrick wrote: > If anyone would like to see a good example of how IDLE code should be > written. I highly suggest you check out the source for PyShell and > PyCrust which is located in roughly... > > HOME\PythonXX\Lib\site-packages\wx-2.8-msw-ansi\wx\py: > ?* shell.py > ?* crust.py > ?* filling.py > > Also run these scripts to see them all in action: > ?* PyAlaCarte.py > ?* PyAlaMode.py UPDATE: For those of you who would like to see the source online here is a link... http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/wx/py From rantingrick at gmail.com Fri Feb 4 13:34:42 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 4 Feb 2011 10:34:42 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> Message-ID: <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> On Feb 4, 3:55?am, flebber wrote: > Enough talk ratingrick where is your feature and request tracker for > your idle fork? How can people assist you in your new idle fork > project? What are your stated project goals & timeline? I am ready flebber but we have a problem. An old IDLE fork project still exists and if i start a new one then folks will probably get confused. We don't need more multiplicity. So, I am asking now that the owners of IDLE fork step forth and offer the site to me or someone who would be interested in restarting the fork with new goals of cleaning up the horrible code base and ambition to maybe do more. We don't want to bloat IDLE but we do want to clean it up. I don't care who *that* person is as long as *they* are willing to push IDLE forward. I would be honored to accept the reigns and lead OR follow someone else's lead. But we need to receive the old idlefork or have them delete the old idle fork as too much confusion will spread with when two idleforks exists. Here is a link to the old idle fork: http://idlefork.sourceforge.net/ From me+list/python at ixokai.io Fri Feb 4 13:49:49 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 04 Feb 2011 10:49:49 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> References: <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> Message-ID: <4D4C4A4D.2030302@ixokai.io> On 2/4/11 10:34 AM, rantingrick wrote: > But we need to receive the old idlefork or > have them delete the old idle fork as too much confusion will spread > with when two idleforks exists. This is nonsense. And probably just another excuse for you to rant instead of actually doing something of any use. IDLEfork was a specific project which ended. It doesn't need to be "taken over" or "deleted" -- it served its purpose and there's nothing wrong with its history being preserved. Your new idea for a project has very different aims and a very different agenda from the idlefork that was. So name your new project something else. reIDLE, maybe. Or unIDLE. Or whatever else. There is no real danger of confusion. Welcome to Open Source. Forking is good, not bad. There is no overmind, no one speaks for the silent majority. Actions may-- may!-- get you some support and followers. Talking will get you none at all. Put your money where your mouth is. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From brenNOSPAMbarn at NObrenSPAMbarn.net Fri Feb 4 14:11:58 2011 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Fri, 4 Feb 2011 19:11:58 +0000 (UTC) Subject: Use the Source Luke References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> Message-ID: rusi wrote: > On Feb 2, 12:32?am, "OKB (not okblacke)" >> ? ? ? ? I think, in general, the less anyone needs to know C even >> exists, the better for Python; likewise, the more that people have >> to mention the existence of C in a Python context, the worse for >> Python. ?This may be a somewhat extreme viewpoint, but that's my >> position. > > In 1990 I wrote a paper elaborating this. > http://portal.acm.org/citation.cfm?id=126471 It is dated (before > python, java, haskell and the internet as we know it today) > It is also dated in the sense that I dont totally agree with the > strong views therein (I was half my age then :-) Very interesting, thanks. I think Python has its own warts comparable to some of those you mention, but not all. What bothers me most is when "practicality beats purity" is invoked, with practicality defined as "doing it this way is faster in C". -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From glicerinu at gmail.com Fri Feb 4 14:17:39 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Fri, 4 Feb 2011 11:17:39 -0800 (PST) Subject: Create classes at runtnime Message-ID: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Hi! I need to create a pretty complex class at runtime. something like this one: (note: "...." means that the number of attributes can be variable) class VirtualUserLimitForm(ModelForm): swap_limit = forms.CharField(max_length=100, initial=monitor1.default_limit) memory_limit = forms.CharField(max_length=100, initial=monitor2.default_limit) ... class Meta: model = model def __init__(self, *args, **kwargs): super(VirtualUserLimitForm, self).__init__(*args, **kwargs) if 'instance' in kwargs: self.fields['swap_limit'].initial = kwargs['instance'].monitoring.filter(monitor=monitor1)[0].current self.fields['memory_limit'].initial = kwargs['instance'].monitoring.filter(monitor=monitor2)[0].current ... I can generate all the needed code as string and then use exec(), but it seems ugly to me. I'm wondering if there is another way more elegant to do that? metaclasses maybe? What is your recommendation? Thanks!! From tjreedy at udel.edu Fri Feb 4 15:05:28 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Feb 2011 15:05:28 -0500 Subject: How to debug a problem with python crashing under windows In-Reply-To: <2ccb4afa-dcdb-4cbf-8d02-247c3e468c02@glegroupsg2000goo.googlegroups.com> References: <334b65cd-fd44-4aa0-9798-8399e786beb7@w36g2000vbi.googlegroups.com> <2ccb4afa-dcdb-4cbf-8d02-247c3e468c02@glegroupsg2000goo.googlegroups.com> Message-ID: On 2/4/2011 11:41 AM, Miki Tebeka wrote: >> With crashing I mean, that windows pops up a screen saying, that >> python.exe failed. >> I do not have any usable trace on stdout / stderr. >> >> What are the best means to analyze such errors? > You can use sys.excepthook to catch uncaught exceptions. See http://pythonwise.blogspot.com/2008/12/crashlog.html for example ;) There likely is no uncaught exception, since such should produce a visible stack trace, certainly if the app is run from a Command Prompt window. Victor Stinner is working on a module for 3.3 that will try to catch crashes and produce some report before everything is gone. It may be up on PyPI before that. -- Terry Jan Reedy From vincent at vincentdavis.net Fri Feb 4 15:21:43 2011 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 4 Feb 2011 13:21:43 -0700 Subject: Download an attachment from an IMAP email In-Reply-To: References: Message-ID: hgc On Thu, Feb 3, 2011 at 6:52 PM, Kushal Kumaran < kushal.kumaran+python at gmail.com > wrote: > On Fri, Feb 4, 2011 at 3:44 AM, Vincent Davis > wrote: > > I have a few emails I am trying to download from my google account. I > seem > > to be getting the message but each of these messages have an attachment. > I > > don't understand what I ned to do to get and save the attachment to a > local > > file. > > Here is what I have so far. > > M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT) > > rc, resp = M.login('xxxxx at xxxx', 'XXXXX') > > print rc, resp > > M.select('[Gmail]/All Mail') > > M.search(None, 'FROM', 'someone at logitech.com') > > #M.fetch(121, '(body[header.fields (subject)])') > > M.fetch(121, '(RFC822)') > > Take a look at the email module. The message_from_string() function > can convert the string representation of the email (as obtained by > M.fetch(121, '(RFC822)') into a message object. > Thanks Vincent > > -- > regards, > kushal > -- Thanks Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From wanderer at dialup4less.com Fri Feb 4 16:08:36 2011 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 4 Feb 2011 13:08:36 -0800 (PST) Subject: using attributes as defaults Message-ID: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> I want to give the option of changing attributes in a method or using the current values of the attributes as the default. class MyClass(): """ my Class """ def __init__(self): """ initialize """ self.a = 3 self.b = 4 def MyMethod(self, a = self.a, b = self.b) """ My Method """ self.a = a self.b = b DoSomething(a, b) The above doesn't work. Is there a way to make it work? Thanks From me+list/python at ixokai.io Fri Feb 4 16:16:43 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 04 Feb 2011 13:16:43 -0800 Subject: using attributes as defaults In-Reply-To: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> References: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> Message-ID: <4D4C6CBB.9000901@ixokai.io> On 2/4/11 1:08 PM, Wanderer wrote: > I want to give the option of changing attributes in a method or using > the current values of the attributes as the default. > > class MyClass(): > """ my Class > """ > def __init__(self): > """ initialize > """ > self.a = 3 > self.b = 4 > > def MyMethod(self, a = self.a, b = self.b) > """ My Method > """ > self.a = a > self.b = b > DoSomething(a, b) > > The above doesn't work. Is there a way to make it work? The normal way to go about it would be to set the a/b arguments to None, like so: def MyMethod(self, a = None, b = None): if a is not None: self.a = a if b is not None: self.b = b DoSomething(self.a, self.b) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From __peter__ at web.de Fri Feb 4 16:17:48 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 04 Feb 2011 22:17:48 +0100 Subject: using attributes as defaults References: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> Message-ID: Wanderer wrote: > I want to give the option of changing attributes in a method or using > the current values of the attributes as the default. > > class MyClass(): > """ my Class > """ > def __init__(self): > """ initialize > """ > self.a = 3 > self.b = 4 > > def MyMethod(self, a = self.a, b = self.b) > """ My Method > """ > self.a = a > self.b = b > DoSomething(a, b) > > The above doesn't work. Is there a way to make it work? No. The defaults are evaluated once, when the method is created, and self.a is only known after the instance has been created. The Python idiom to achieve what you want is def MyMethod(self, a=None): if a is not None: self.a = a If None is a valid value for self.a you can use a custom sentinel instead: missing = object() class MyClass: def MyMethod(self, a=missing): if a is not missing: self.a = a From emile at fenx.com Fri Feb 4 16:20:06 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 Feb 2011 13:20:06 -0800 Subject: using attributes as defaults In-Reply-To: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> References: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> Message-ID: On 2/4/2011 1:08 PM Wanderer said... > I want to give the option of changing attributes in a method or using > the current values of the attributes as the default. > > class MyClass(): > """ my Class > """ > def __init__(self): > """ initialize > """ > self.a = 3 > self.b = 4 > > def MyMethod(self, a = self.a, b = self.b) > """ My Method > """ > self.a = a > self.b = b > DoSomething(a, b) The typical approach would be to use None: def myMethod(self,a=None,b=None): if a is None: a=self.a ... Emile > > The above doesn't work. Is there a way to make it work? > > Thanks > From __peter__ at web.de Fri Feb 4 16:32:37 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 04 Feb 2011 22:32:37 +0100 Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Message-ID: Marc Aymerich wrote: > I need to create a pretty complex class at runtime. something like > this one: I have a hunch that you've never heard the famous Kernighan quote: "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" Or that if you've heard it you don't heed it. > (note: "...." means that the number of attributes can be variable) > > class VirtualUserLimitForm(ModelForm): > swap_limit = forms.CharField(max_length=100, > initial=monitor1.default_limit) > memory_limit = forms.CharField(max_length=100, > initial=monitor2.default_limit) > ... > > class Meta: > model = model > > def __init__(self, *args, **kwargs): > super(VirtualUserLimitForm, self).__init__(*args, **kwargs) > if 'instance' in kwargs: > self.fields['swap_limit'].initial = > kwargs['instance'].monitoring.filter(monitor=monitor1)[0].current > self.fields['memory_limit'].initial = > kwargs['instance'].monitoring.filter(monitor=monitor2)[0].current > ... > > I can generate all the needed code as string and then use exec(), but > it seems ugly to me. I'm wondering if there is another way more > elegant to do that? metaclasses maybe? The metaclass does indeed take a dictionary argument where you can provide class attributes, e. g.: >>> C = type("C", (), dict(a=1, b=lambda self: 42)) >>> C().a, C().b() (1, 42) > What is your recommendation? Find something that is simple and robust. Something else. Peter From pavlovevidence at gmail.com Fri Feb 4 17:38:51 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 4 Feb 2011 14:38:51 -0800 (PST) Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Message-ID: <0d20f092-ef77-4acb-a807-0b7790050b02@u11g2000prk.googlegroups.com> On Feb 4, 1:32?pm, Peter Otten <__pete... at web.de> wrote: > Marc Aymerich wrote: > > I need to create a pretty complex class at runtime. something like > > this one: > > I have a hunch that you've never heard the famous Kernighan quote: > > "Everyone knows that debugging is twice as hard as writing a program in the > first place. So if you're as clever as you can be when you write it, how > will you ever debug it?" > > Or that if you've heard it you don't heed it. [snip] > > What is your recommendation? > > Find something that is simple and robust. Something else. I've done things like this before, and I would say the Kernigan quote is not appropriate here, and the implication that isn't not simple and robust is incorrect. It's repetitive code like the OP posted that's complex and flimsy. Repetitive code is the exact opposite of the DRY principle, and there's a reason DRY is one of the most often cited principles here. Using advanced techniques like metaclasses to exploit the similarity to reduce or eliminate the repetitiveness can, if done well, simplify code. By a lot. Advanced is not the same thing as complex. In this particular case I'd say the recommendation to do something else is a good one, but it's not true in general. Carl Banks From pavlovevidence at gmail.com Fri Feb 4 17:51:46 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 4 Feb 2011 14:51:46 -0800 (PST) Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Message-ID: <8d85d012-e347-4f3e-901c-3ffea7b9eea8@m16g2000prc.googlegroups.com> On Feb 4, 11:17?am, Marc Aymerich wrote: > Hi! > I need to create a pretty complex class at runtime. something like > this one: > > (note: "...." means that the number of attributes can be variable) > > class VirtualUserLimitForm(ModelForm): > ? ? swap_limit = forms.CharField(max_length=100, > initial=monitor1.default_limit) > ? ? memory_limit = forms.CharField(max_length=100, > initial=monitor2.default_limit) > ? ? ... > > ? ? class Meta: > ? ? ? ? model = model > > ? ? def __init__(self, *args, **kwargs): > ? ? ? ? super(VirtualUserLimitForm, self).__init__(*args, **kwargs) > ? ? ? ? if 'instance' in kwargs: > ? ? ? ? ? ? self.fields['swap_limit'].initial = > kwargs['instance'].monitoring.filter(monitor=monitor1)[0].current > ? ? ? ? ? ? self.fields['memory_limit'].initial = > kwargs['instance'].monitoring.filter(monitor=monitor2)[0].current > ? ? ? ? ? ? ... > > I can generate all the needed code as string and then use exec(), but > it seems ugly to me. I'm wondering if there is another way more > elegant to do that? ?metaclasses maybe? What is your recommendation? I'd recommend against using metaclasses (in the normal way) with Django ORM, since it (and pretty much all ORMs) already makes heavy use of metaclasses, and I doubt those metaclasses were designed to share metaclassing duties. At a minimum you'd have to derive your own metaclasses from Djangos, and that's not likely to work out well at all. The right way to do this might be to reorganize your database. It seems like you have all kinds of tables with different sets of columns, and the tables themselves are dynamic? Like if you get some data somewhere and it doesn't fit into an existing schema you make a new table for it? If that's the case then you'd be better off, perhaps, to reorganize the tables into some kind of association list. Put the "relational" aspect to use. (Left as an exercise for now but if you want pointers feel free to follow up.) But maybe you have no control of the tables; you simply have a lot of them and want to cut down on repetition. Then I think a factory function that builds a dict and passes it to type() would be reasonable. See the documentation of type() for explanation of arguments. def create_user_form(name,fields,_model): class Meta: model = _model dct = { 'Meta': Meta } for field in fields: dct[field] = forms.CharField(max_length=100, > initial=monitor1.default_limit) return type(name,(ModelForm,),dct) Carl Banks From ian.g.kelly at gmail.com Fri Feb 4 17:56:48 2011 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 4 Feb 2011 14:56:48 -0800 (PST) Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Message-ID: <2ab85afb-1e23-4037-8d3a-bfb1138c1c8c@u3g2000vbe.googlegroups.com> On Feb 4, 2:32?pm, Peter Otten <__pete... at web.de> wrote: > > (note: "...." means that the number of attributes can be variable) > > > class VirtualUserLimitForm(ModelForm): > > ? ? swap_limit = forms.CharField(max_length=100, > > initial=monitor1.default_limit) > > ? ? memory_limit = forms.CharField(max_length=100, > > initial=monitor2.default_limit) > > ? ? ... > > > ? ? class Meta: > > ? ? ? ? model = model > > > ? ? def __init__(self, *args, **kwargs): > > ? ? ? ? super(VirtualUserLimitForm, self).__init__(*args, **kwargs) > > ? ? ? ? if 'instance' in kwargs: > > ? ? ? ? ? ? self.fields['swap_limit'].initial = > > kwargs['instance'].monitoring.filter(monitor=monitor1)[0].current > > ? ? ? ? ? ? self.fields['memory_limit'].initial = > > kwargs['instance'].monitoring.filter(monitor=monitor2)[0].current > > ? ? ? ? ? ? ... > > > I can generate all the needed code as string and then use exec(), but > > it seems ugly to me. I'm wondering if there is another way more > > elegant to do that? ?metaclasses maybe? > > The metaclass does indeed take a dictionary argument where you can provide > class attributes, e. g.: > > >>> C = type("C", (), dict(a=1, b=lambda self: 42)) > >>> C().a, C().b() > > (1, 42) This approach will basically work, but since you're subclassing the Django ModelForm, note that it already has its own metaclass: >>> django.forms.ModelForm.__class__ So you will need to either subclass ModelFormMetaclass for your metaclass and override the __init__ method, or modify what Peter posted like so: >>> C = django.forms.ModelForm.__class__("VirtualUserLimitForm", (django.forms.ModelForm,), dict(a=1, b=lambda self: 42)) Cheers, Ian From rantingrick at gmail.com Fri Feb 4 18:01:02 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 4 Feb 2011 15:01:02 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> Message-ID: On Feb 4, 12:49?pm, Stephen Hansen wrote: > On 2/4/11 10:34 AM, rantingrick wrote: > > > But we need to receive the old idlefork or > > have them delete the old idle fork as too much confusion will spread > > with when two idleforks exists. > > This is nonsense. And probably just another excuse for you to rant > instead of actually doing something of any use. Thats a very *ironic* thing to say Stephan! > IDLEfork was a specific project which ended. Exactly. The key word here is ENDED! The changes were rolled back into Pythons stdlib. > It doesn't need to be > "taken over" or "deleted" -- it served its purpose and there's nothing > wrong with its history being preserved. history translated: old asss shmit > Your new idea for a project has > very different aims and a very different agenda from the idlefork that was. No, both my idea and the old idea was to improve IDLE. What is so different about that? > So name your new project something else. reIDLE, maybe. Or unIDLE. Or > whatever else. OK, name yourself something else, like naysayer, gossip-hound, or troll. > Put your money where your mouth is. ditto! From slafs.e at gmail.com Fri Feb 4 18:14:24 2011 From: slafs.e at gmail.com (Slafs) Date: Fri, 4 Feb 2011 15:14:24 -0800 (PST) Subject: itertools.groupby usage to get structured data Message-ID: <7c46612d-d435-4e4f-bfa0-e7dd5918f66c@24g2000yqa.googlegroups.com> Hi there! I'm having trouble to wrap my brain around this kind of problem: What I have : 1) list of dicts 2) list of keys that i would like to be my grouping arguments of elements from 1) 3) list of keys that i would like do "aggregation" on the elements of 1) with some function e.g. sum For instance i got: 1) [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 }, { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 }, {'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0}, ... ] 2) ['g1', 'g2'] 3) ['s_v1', 's_v2'] To be precise 1) is a result of a values_list method from a QuerySet in Django; 2) is the arguments for that method; 3) those are the annotation keys. so 1) is a result of: qs.values_list('g1', 'g2').annotate(s_v1=Sum('v1'), s_v2=Sum('v2')) What i want to have is: a "big" nested dictionary with 'g1' values as 1st level keys and a dictionary of aggregates and "subgroups" in it. In my example it would be something like this: { 1 : { 's_v1' : 7.0, 's_v2' : 6.5, 'g2' :{ 8 : { 's_v1' : 5.0, 's_v2' : 3.5 }, 9 : { 's_v1' : 2.0, 's_v2' : 3.0 } } }, 2 : { 's_v1' : 6.0, 's_v2' : 8.0, 'g2' : { 8 : { 's_v1' : 6.0, 's_v2' : 8.0} } }, ... } # notice the summed values of s_v1 and s_v2 when g1 == 1 I was looking for a solution that would let me do that kind of grouping with variable lists of 2) and 3) i.e. having also 'g3' as grouping element so the 'g2' dicts could also have their own "subgroup" and be even more nested then. I was trying something with itertools.groupby and updating nested dicts, but as i was writing the code it started to feel too verbose to me :/ Do You have any hints maybe? because i'm kind of stucked :/ Regards S?awek From me+list/python at ixokai.io Fri Feb 4 18:24:06 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 04 Feb 2011 15:24:06 -0800 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: References: <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> Message-ID: <4D4C8A96.40600@ixokai.io> On 2/4/11 3:01 PM, rantingrick wrote: >> Put your money where your mouth is. > > ditto! I thought as much. My money is where my mouth is: but that is not IDLE, as I have no use for it and no interest in it at all. The status quo with regards to IDLE is satisfactory to me. You're the one talking so much about how it needs to improve. So do it. Get started. Now. But you'll just find another excuse to rant on like you always do, and be basically useless. Me, I _have_ contributed patches: I have released actual code that actual people have found actually useful. I do run two build slaves and proactively try to assist in resolving issues that come up with Python's testing (usually: ouch, there's a lot of red at the moment, must get cracking) and stability. So, yeah. You're the hypocrite here, man. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From anikom15 at gmail.com Fri Feb 4 18:24:45 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 04 Feb 2011 15:24:45 -0800 Subject: shared python module ? In-Reply-To: References: Message-ID: <1296861885.20786.2.camel@localhost.localdomain> On Fri, 2011-02-04 at 22:36 +0530, km wrote: > Hi all, > > I have two version of python 2.6 and 2.7. > Now Is there any way that I install a python module (from pypi) and > import it across both the versions ? > > regards, > KM Simply install it twice, for each version, e.g.: % cd % python2.6 setup.py install % python2.7 setup.py install Each version of Python has its own directory for modules. -------------- next part -------------- An HTML attachment was scrubbed... URL: From anikom15 at gmail.com Fri Feb 4 18:32:08 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 04 Feb 2011 15:32:08 -0800 Subject: using attributes as defaults In-Reply-To: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> References: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> Message-ID: <1296862328.20786.7.camel@localhost.localdomain> On Fri, 2011-02-04 at 13:08 -0800, Wanderer wrote: > I want to give the option of changing attributes in a method or using > the current values of the attributes as the default. > > class MyClass(): > """ my Class > """ > def __init__(self): > """ initialize > """ > self.a = 3 > self.b = 4 > > def MyMethod(self, a = self.a, b = self.b) > """ My Method > """ > self.a = a > self.b = b > DoSomething(a, b) > > The above doesn't work. Is there a way to make it work? > > Thanks > This doesn't work because you can't reference keyword arguments in the keyword argument array. This will work: class MyClass: def __init__(self): """ initialize Really? These are the worst docstrings ever. """ self.a = 3 self.b = 4 def MyMethod(self, a=None, b=None) if a is not None: self.a = a if b is not None: self.b = b DoSomething(a, b) -------------- next part -------------- An HTML attachment was scrubbed... URL: From flo at chaoflow.net Fri Feb 4 19:05:50 2011 From: flo at chaoflow.net (Florian Friesdorf) Date: Sat, 5 Feb 2011 01:05:50 +0100 Subject: Plumber, an alternative to mixin-based subclassing Message-ID: <20110205000550.GA6243@eve.chaoflow.net> An alternative to mixin-based subclassing: http://pypi.python.org/pypi/plumber -- Florian Friesdorf GPG FPR: 7A13 5EEE 1421 9FC2 108D BAAF 38F8 99A3 0C45 F083 Jabber/XMPP: flo at chaoflow.net IRC: chaoflow on freenode,ircnet,blafasel,OFTC From vze26m98 at optonline.net Fri Feb 4 19:32:09 2011 From: vze26m98 at optonline.net (Charles Turner) Date: Fri, 4 Feb 2011 19:32:09 -0500 Subject: Algorithm for generating pitch-class sets in prime form References: Message-ID: <2011020419320961127-vze26m98@optonlinenet> Hi- Do you knowof Christopher Ariza's AthenaCL? HTH, Charles From steve+comp.lang.python at pearwood.info Fri Feb 4 19:49:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Feb 2011 00:49:53 GMT Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Message-ID: <4d4c9eb1$0$29990$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Feb 2011 11:17:39 -0800, Marc Aymerich wrote: > Hi! > I need to create a pretty complex class at runtime. something like this > one: > > (note: "...." means that the number of attributes can be variable) > > class VirtualUserLimitForm(ModelForm): > swap_limit = forms.CharField(max_length=100, > initial=monitor1.default_limit) > memory_limit = forms.CharField(max_length=100, > initial=monitor2.default_limit) > ... [...] > I can generate all the needed code as string and then use exec(), but it > seems ugly to me. I'm wondering if there is another way more elegant to > do that? metaclasses maybe? What is your recommendation? Just add in the class attributes you want after creating the class. class VirtualUserLimitForm(ModelForm): pass f = forms.CharField # alias for brevity for name, value in [ ('swap_limit', f(max_length=100, initial=monitor1.default_limit)), ('memory_limit', f(max_length=100, initial=monitor2.default_limit)), ('spam', 'spam spam spam spam'), ('eggs', 'fried sunny side up'), ]: setattr(VirtualUserLimitForm, name, value) There's probably a name for this sort of technique, and an entire chapter in "Design Patterns For People With Too Much Time On Their Hands" (15th edition), but I don't remember it :) -- Steven From ian.g.kelly at gmail.com Fri Feb 4 20:19:23 2011 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 4 Feb 2011 17:19:23 -0800 (PST) Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> <4d4c9eb1$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6d3e45e3-5160-49a3-ad4a-6bbcdd425768@k22g2000yqh.googlegroups.com> On Feb 4, 5:49?pm, Steven D'Aprano wrote: > Just add in the class attributes you want after creating the class. > > class VirtualUserLimitForm(ModelForm): > ? ? pass > > f = forms.CharField ?# alias for brevity > for name, value in [ > ? ? ('swap_limit', f(max_length=100, initial=monitor1.default_limit)), > ? ? ('memory_limit', f(max_length=100, initial=monitor2.default_limit)), > ? ? ('spam', 'spam spam spam spam'), > ? ? ('eggs', 'fried sunny side up'), > ? ? ]: > ? ? setattr(VirtualUserLimitForm, name, value) This would probably cause some problems with the Django metaclass. It inspects the class dictionary for fields at the time the class in constructed, and so it would miss any fields added after construction time. From latias100 at gmail.com Fri Feb 4 20:56:56 2011 From: latias100 at gmail.com (- -) Date: Fri, 4 Feb 2011 20:56:56 -0500 Subject: Tk Tablelist embedded window Message-ID: I have some really Tcl code which I would like to run in Python: package require Tk package require Tablelist proc main {} { tablelist::tablelist .t -columns {0 Test} -stretch 1 .t insert end {{} {}} .t cellconfigure end,0 -window {createWindow} .t insert end {{} {}} .t cellconfigure end,0 -window {createWindow} pack .t -side top -fill both -expand true } proc createWindow {t row col path} { set width [.t columnwidth 0 -total] button $path -width $width } main This is what I have in Python: from Tkinter import * import tktablelist def createWindow(t,row,col,path): b = Button(path) def main(): t = tktablelist.TableList(root,columns = (0,' ')) t.insert(END, (None, None)) t.cellconfigure("end,0",window=createWindow) t.pack() root = Tk() main() root.mainloop() I get an error because I don't know how to format the "window" for createWindow. What should I do to embed the button in the Tablelist? I am using the Tablelist wrapper from this website: http://tkinter.unpythonic.net/wiki/TableListWrapper -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Feb 4 21:10:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Feb 2011 02:10:30 GMT Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> <4d4c9eb1$0$29990$c3e8da3$5496439d@news.astraweb.com> <6d3e45e3-5160-49a3-ad4a-6bbcdd425768@k22g2000yqh.googlegroups.com> Message-ID: <4d4cb196$0$29990$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Feb 2011 17:19:23 -0800, Ian wrote: > On Feb 4, 5:49?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Just add in the class attributes you want after creating the class. [...] > This would probably cause some problems with the Django metaclass. It > inspects the class dictionary for fields at the time the class in > constructed, and so it would miss any fields added after construction > time. What Django metaclass? The OP didn't say anything about using Django. -- Steven From steve+comp.lang.python at pearwood.info Fri Feb 4 21:27:43 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Feb 2011 02:27:43 GMT Subject: itertools.groupby usage to get structured data References: <7c46612d-d435-4e4f-bfa0-e7dd5918f66c@24g2000yqa.googlegroups.com> Message-ID: <4d4cb59e$0$29990$c3e8da3$5496439d@news.astraweb.com> On Fri, 04 Feb 2011 15:14:24 -0800, Slafs wrote: > Hi there! > > I'm having trouble to wrap my brain around this kind of problem: Perhaps you should consider backing up and staring from somewhere else with different input data, or changing the requirements. Just a thought. > What I have : > 1) list of dicts > 2) list of keys that i would like to be my grouping arguments of > elements from 1) > 3) list of keys that i would like do "aggregation" on the elements > of 1) with some function e.g. sum You start with data: dicts = [ {'g1': 1, 'g2': 8, 's_v1': 5.0, 's_v2': 3.5}, {'g1': 1, 'g2': 9, 's_v1': 2.0, 's_v2': 3.0}, {'g1': 2, 'g2': 8, 's_v1': 6.0, 's_v2': 8.0} ] It sometimes helps me to think about data structures by drawing them out. In this case, you have what is effectively a two-dimensional table: g1 g2 s_v1 s_v2 === === ===== ==== 1 8 5.0 3.5 1 9 2.0 3.0 2 8 6.0 8.0 Nice and simple. But the result you want is a bit more complex -- it's a dict of dicts of dicts: {1: {'s_v1': 7.0, 's_v2': 6.5, 'g2': {8: {'s_v1': 5.0, 's_v2': 3.5}, 9: {'s_v1': 2.0, 's_v2': 3.0} }}, 2: {'s_v1': 6.0, 's_v2': 8.0, 'g2': {8: {'s_v1' : 6.0, 's_v2': 8.0} }}} (I quote from the Zen of Python: "Flat is better than nested." Hmmm.) which is equivalent to a *four* dimensional table, which is a bit hard to write out :) Here's a two-dimensional projection of a single slice with key = 1: s_v1 s_v2 g2 ===== ===== ===== 7.0 6.5 | s_v1 s_v2 --------------- 8 | 5.0 3.5 9 | 2.0 3.0 Does this help you to either (1) redesign your data structures, or (2) work out how to go from there? [...] > I was looking for a solution that would let me do that kind of grouping > with variable lists of 2) and 3) i.e. having also 'g3' as grouping > element so the 'g2' dicts could also have their own "subgroup" and be > even more nested then. I was trying something with itertools.groupby and > updating nested dicts, but as i was writing the code it started to feel > too verbose to me :/ I don't think groupby is the tool you want. It groups *consecutive* items in sequences: >>> from itertools import groupby >>> for key, it in groupby([1,1,1,2,3,4,3,3,3,5,1]): ... print(key, list(it)) ... 1 [1, 1, 1] 2 [2] 3 [3] 4 [4] 3 [3, 3, 3] 5 [5] 1 [1] Except for the name, I don't see any connection between this and what you want to do. The approach I would take is a top-down approach: dicts = [ ... ] # list of dicts, as above. result = {} for d in dicts: # process each dict in isolation temp = process(d) merge(result, temp) merge() hopefully should be straight forward, and process only needs to look at one dict at a time. -- Steven From clp2 at rebertia.com Fri Feb 4 21:49:06 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 4 Feb 2011 18:49:06 -0800 Subject: Create classes at runtnime In-Reply-To: <4d4cb196$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> <4d4c9eb1$0$29990$c3e8da3$5496439d@news.astraweb.com> <6d3e45e3-5160-49a3-ad4a-6bbcdd425768@k22g2000yqh.googlegroups.com> <4d4cb196$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Feb 4, 2011 at 6:10 PM, Steven D'Aprano wrote: > On Fri, 04 Feb 2011 17:19:23 -0800, Ian wrote: >> On Feb 4, 5:49?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: >>> Just add in the class attributes you want after creating the class. > [...] >> This would probably cause some problems with the Django metaclass. ?It >> inspects the class dictionary for fields at the time the class in >> constructed, and so it would miss any fields added after construction >> time. > > What Django metaclass? The OP didn't say anything about using Django. His code mentions "forms.CharField" and declares a nested class named "Meta"; this is indicative of Django. Cheers, Chris -- http://blog.rebertia.com From no.email at nospam.invalid Fri Feb 4 23:58:53 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 04 Feb 2011 20:58:53 -0800 Subject: itertools.groupby usage to get structured data References: <7c46612d-d435-4e4f-bfa0-e7dd5918f66c@24g2000yqa.googlegroups.com> Message-ID: <7xy65vm60i.fsf@ruckus.brouhaha.com> Slafs writes: > What i want to have is: > a "big" nested dictionary with 'g1' values as 1st level keys and a > dictionary of aggregates and "subgroups" in it.... > > I was looking for a solution that would let me do that kind of > grouping with variable lists of 2) and 3) i.e. having also 'g3' as > grouping element so the 'g2' dicts could also have their own > "subgroup" and be even more nested then. > I was trying something with itertools.groupby and updating nested > dicts, but as i was writing the code it started to feel too verbose to > me :/ > > Do You have any hints maybe? because i'm kind of stucked :/ I'm not sure I understood the problem and it would help if you gave sample data with the deeper nesting that you describe. But the following messy code matches the sample that you did give: from pprint import pprint from itertools import groupby x1 = [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 }, { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 }, { 'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0} ] x2 = ['g1', 'g2'] x3 = ['s_v1', 's_v2'] def agg(xdata, group_keys, agg_keys): if not group_keys: return {} k0, ks = group_keys[0], group_keys[1:] r = {} def gk(d): return d[k0] for k, g in groupby(sorted(xdata, key=gk), gk): gs = list(g) aggs = dict((ak,sum(d[ak] for d in gs)) for ak in agg_keys) r[k] = aggs if ks: r[k][ks[0]] = agg(gs,group_keys[1:], agg_keys) return r pprint (agg(x1, x2, x3)) From rustompmody at gmail.com Sat Feb 5 00:20:09 2011 From: rustompmody at gmail.com (rusi) Date: Fri, 4 Feb 2011 21:20:09 -0800 (PST) Subject: Use the Source Luke References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> Message-ID: <30a7836b-32b6-4675-b0a8-664832f8a74b@y4g2000prh.googlegroups.com> On Feb 5, 12:11?am, "OKB (not okblacke)" wrote: > > ? ? ? ? Very interesting, thanks. ?I think Python has its own warts > comparable to some of those you mention, but not all. ?What bothers me > most is when "practicality beats purity" is invoked, with practicality > defined as "doing it this way is faster in C". Yes Knuth is worshipped but his advice is not heeded http://en.wikipedia.org/wiki/Program_optimization#When_to_optimize From stefan_ml at behnel.de Sat Feb 5 01:27:50 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 05 Feb 2011 07:27:50 +0100 Subject: Use the Source Luke In-Reply-To: References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <87tygs1v6g.fsf@benfinney.id.au> Message-ID: OKB (not okblacke), 04.02.2011 20:11: > I think Python has its own warts > comparable to some of those you mention, but not all. What bothers me > most is when "practicality beats purity" is invoked, with practicality > defined as "doing it this way is faster in C". Most of that should be gone in Python 3. There's also the practicality in the sense of "someone has to write the code". Both are certainly common in every open source developer community, including python-dev, if you replace "C" by "the right language in the given context". But I must say that I rarely read either of the two being used as common meanings for "practicality" on python-dev. That term is very user focussed in the Python community. Stefan From sjmachin at lexicon.net Sat Feb 5 03:01:00 2011 From: sjmachin at lexicon.net (John Machin) Date: Sat, 5 Feb 2011 00:01:00 -0800 (PST) Subject: python crash problem References: <701afd55-9ba3-4dc8-91c9-e6d5065266c5@x11g2000yqc.googlegroups.com> Message-ID: <6df556ef-aba6-4989-aba4-421e9f8ffe99@y4g2000prh.googlegroups.com> On Feb 3, 8:21?am, Terry Reedy wrote: > On 2/2/2011 2:19 PM, Yelena wrote: > . > > When having a problem with a 3rd party module, not part of the stdlib, > you should give a source. > ? ?http://sourceforge.net/projects/dbfpy/ > This appears to be a compiled extension. Nearly always, when Python > crashes running such, it is a problem with the extension. So you > probably need to direct your question to the author or a project mailing > list if there is one. It has always appeared to me to be a pure-Python package. There are no .c or .pyx files in the latest source (.tgz) distribution. The Windows installer installs only files whose extensions match "py[co]?". From flebber.crue at gmail.com Sat Feb 5 04:44:54 2011 From: flebber.crue at gmail.com (flebber) Date: Sat, 5 Feb 2011 01:44:54 -0800 (PST) Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> Message-ID: <2978ccbc-d40f-49e5-a8b7-516064985b88@i14g2000prm.googlegroups.com> On Feb 5, 10:24?am, Stephen Hansen wrote: > On 2/4/11 3:01 PM, rantingrick wrote: > > >> Put your money where your mouth is. > > > ditto! > > I thought as much. > > My money is where my mouth is: but that is not IDLE, as I have no use > for it and no interest in it at all. The status quo with regards to IDLE > is satisfactory to me. > > You're the one talking so much about how it needs to improve. So do it. > Get started. Now. > > But you'll just find another excuse to rant on like you always do, and > be basically useless. > > Me, I _have_ contributed patches: I have released actual code that > actual people have found actually useful. I do run two build slaves and > proactively try to assist in resolving issues that come up with Python's > testing (usually: ouch, there's a lot of red at the moment, must get > cracking) and stability. > > So, yeah. You're the hypocrite here, man. > > -- > > ? ?Stephen Hansen > ? ?... Also: Ixokai > ? ?... Mail: me+list/python (AT) ixokai (DOT) io > ? ?... Blog:http://meh.ixokai.io/ > > ?signature.asc > < 1KViewDownload Idlefork isn't dead to rick! just pining for the alps! From jackchungchiehyu at googlemail.com Sat Feb 5 05:19:15 2011 From: jackchungchiehyu at googlemail.com (Jack Yu) Date: Sat, 5 Feb 2011 01:19:15 -0900 Subject: psd estimation no matplotlib Message-ID: Hi all, Is there a function psd() for estimating power spectral density that is not dependent on the importing of matplotlib or pylab, like there is numpy.linalg.svd() to pylab.svd(). I would like to run some codes which estimate psd on the computing nodes on a cluster, but the system administrator says that it is impractical to install matplotlib on all of them, because it requires X window, which takes up a lot of memory, which the computing nodes do not have. Thanks for any help in advance. Cheers, Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From adi at lspl.net Sat Feb 5 05:33:34 2011 From: adi at lspl.net (sniffer) Date: Sat, 5 Feb 2011 02:33:34 -0800 (PST) Subject: Unable to register com component built with python2.7 Message-ID: <262cf3dd-031b-49a6-a483-8da4bf26cb51@o18g2000prh.googlegroups.com> Hi all, I have built a com component using python2.7 on win 7 but the component refuses to register ,every time i try to register it says the specified module could not be found unable to load python.dll ,i also tried building the same com server with python2.7 again on a win- xp system but to no avail ,i even tried building and registring the com server after removing all imports and just leaving 1 function which returns nothing but the string "hello world" any pointers would be great thanks From slafs.e at gmail.com Sat Feb 5 05:34:26 2011 From: slafs.e at gmail.com (Slafs) Date: Sat, 5 Feb 2011 02:34:26 -0800 (PST) Subject: itertools.groupby usage to get structured data References: <7c46612d-d435-4e4f-bfa0-e7dd5918f66c@24g2000yqa.googlegroups.com> <7xy65vm60i.fsf@ruckus.brouhaha.com> Message-ID: On 5 Lut, 05:58, Paul Rubin wrote: > Slafs writes: > > What i want to have is: > > a "big" nested dictionary with 'g1' values as 1st level keys and a > > dictionary of aggregates and "subgroups" in it.... > > > I was looking for a solution that would let me do that kind of > > grouping with variable lists of 2) and 3) i.e. having also 'g3' as > > grouping element so the 'g2' dicts could also have their own > > "subgroup" and be even more nested then. > > I was trying something with itertools.groupby and updating nested > > dicts, but as i was writing the code it started to feel too verbose to > > me :/ > > > Do You have any hints maybe? because i'm kind of stucked :/ > > I'm not sure I understood the problem and it would help if you gave > sample data with the deeper nesting that you describe. ?But the > following messy code matches the sample that you did give: > > ? ? from pprint import pprint > ? ? from itertools import groupby > > ? ? x1 = [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 }, > ? ? ? ? ? ? ? { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 }, > ? ? ? ? ? ? ? { 'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0} > ? ? ? ? ? ? ? ] > ? ? x2 = ['g1', 'g2'] > ? ? x3 = ['s_v1', 's_v2'] > > ? ? def agg(xdata, group_keys, agg_keys): > ? ? ? ? if not group_keys: > ? ? ? ? ? ? return {} > ? ? ? ? k0, ks = group_keys[0], group_keys[1:] > ? ? ? ? r = {} > ? ? ? ? def gk(d): return d[k0] > ? ? ? ? for k, g in groupby(sorted(xdata, key=gk), gk): > ? ? ? ? ? ? gs = list(g) > ? ? ? ? ? ? aggs = dict((ak,sum(d[ak] for d in gs)) for ak in agg_keys) > ? ? ? ? ? ? r[k] = aggs > ? ? ? ? ? ? if ks: > ? ? ? ? ? ? ? ? r[k][ks[0]] = agg(gs,group_keys[1:], agg_keys) > ? ? ? ? return r > > ? ? pprint (agg(x1, x2, x3)) Thank you both Steven and Paul for your replies. @Steven: > Perhaps you should consider backing up and staring from somewhere else > with different input data, or changing the requirements. Just a thought. I think it's not the issue. The data as you noticed i well structured (as a table for instance) and I don't think I can go better than that. > I don't think groupby is the tool you want. It groups *consecutive* items > in sequences: I was using groupby just like in Paul's code. @Paul: OMG. I think this is it! (getting my jaw from the floor...) The funny part is that I was kind of close to this solution ;). I was considering the use of recursion for this. Thank You so much! From fetchinson at googlemail.com Sat Feb 5 06:46:48 2011 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sat, 5 Feb 2011 12:46:48 +0100 Subject: Use the Source Luke In-Reply-To: <9e25c9bf-4d8b-4484-b8fc-2bfaf6b5820c@n36g2000pre.googlegroups.com> References: <094f6fc5-7242-46c7-b454-4cb29d0c6ef9@q40g2000prh.googlegroups.com> <9e25c9bf-4d8b-4484-b8fc-2bfaf6b5820c@n36g2000pre.googlegroups.com> Message-ID: > For the Python world though, there does seem > to have been a change. A decade ago in this newsgroup, there were > frequent references to standard library source. I don't see that > much anymore. Popularity has a price. A decade ago only hackers were exposed to python who are happy to chat about the source code but these days average computer users (my grandma) frequently come across python and ask questions from a user perspective. So I'd think your observation is correct that the ratio of source related posts to non-source related posts on this list went down but the reason is not because the total number of source related questions decreased but because the total number of non-source related questions increased. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From glicerinu at gmail.com Sat Feb 5 07:06:41 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Sat, 5 Feb 2011 04:06:41 -0800 (PST) Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Message-ID: <7ee6a8c0-4051-4f46-83f3-1c192052311a@d2g2000yqn.googlegroups.com> Thank you all for the answers! I'll try to give you the context in which I need to generate classes like this. I'm developing a reusable control panel for an ISP. I have several modules (VirtualUser, SystemUser, VPS, VirtualHost, ...) and they all share the fact that you can have limits on resource consumption. for example. VPS: has limits on swap, memory, cpu and disk. SystemUser: has limits on disk and traffic. As all modules share this property of being limited I have decided to split the limit functionality in a separate module (called resources). Resources are associated dinamically with (vps, systemuser ...) through a Monitor class. So it's up to you decide what limits you are interested to put in the VPS or in the SystemUser ... So when you attach the "disk limit" to SystemUser model is necessary to create a web form for SystemUser a bit different than if you decide to have disk and traffic limits. That is what my posted code is supposed to do. Do you think that I am on the wrong way designing the control panel like this? Btw, I've seen several interesting ideas to create the class dinamically (with class factorys, MetaClass, dictionaries ..), but I have not yet clear whether this will be usefull for create the __init__ function at runtime too. Any clue on this? Many, many thanks!! :) Marc From __peter__ at web.de Sat Feb 5 07:09:31 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 05 Feb 2011 13:09:31 +0100 Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> <0d20f092-ef77-4acb-a807-0b7790050b02@u11g2000prk.googlegroups.com> Message-ID: Carl Banks wrote: > On Feb 4, 1:32 pm, Peter Otten <__pete... at web.de> wrote: >> Marc Aymerich wrote: >> > I need to create a pretty complex class at runtime. something like >> > this one: >> >> I have a hunch that you've never heard the famous Kernighan quote: >> >> "Everyone knows that debugging is twice as hard as writing a program in >> the first place. So if you're as clever as you can be when you write it, >> how will you ever debug it?" >> >> Or that if you've heard it you don't heed it. > > [snip] > >> > What is your recommendation? >> >> Find something that is simple and robust. Something else. > > > I've done things like this before, and I would say the Kernigan quote > is not appropriate here, and the implication that isn't not simple and > robust is incorrect. It's repetitive code like the OP posted that's > complex and flimsy. Repetitive code is the exact opposite of the DRY > principle, and there's a reason DRY is one of the most often cited > principles here. > > Using advanced techniques like metaclasses to exploit the similarity > to reduce or eliminate the repetitiveness can, if done well, simplify > code. By a lot. > > Advanced is not the same thing as complex. > > > In this particular case I'd say the recommendation to do something > else is a good one, but it's not true in general. The trouble with metaclasses is that they are not completely transparent. Instead of two levels (class and instance) you have to consider three. Steven D'Aprano has involuntarily given an example of what may go wrong. Marc has asked another question with a problem that could be attacked with a metaclass before. Had he been comfortable with metaclasses by now we wouldn't have seen the above post. So he is operating at the limits of his current understanding of Python in an area where it is not unlikely that he'll run into unexpected side effects of the django database wrapper. I think a reminder that he has to debug the whole thing is in order ;) Peter From __peter__ at web.de Sat Feb 5 07:12:36 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 05 Feb 2011 13:12:36 +0100 Subject: itertools.groupby usage to get structured data References: <7c46612d-d435-4e4f-bfa0-e7dd5918f66c@24g2000yqa.googlegroups.com> Message-ID: Slafs wrote: > Hi there! > > I'm having trouble to wrap my brain around this kind of problem: > > What I have : > 1) list of dicts > 2) list of keys that i would like to be my grouping arguments of > elements from 1) > 3) list of keys that i would like do "aggregation" on the elements > of 1) with some function e.g. sum > > For instance i got: > 1) [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 }, > { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 }, > {'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0}, ... ] > 2) ['g1', 'g2'] > 3) ['s_v1', 's_v2'] > > To be precise 1) is a result of a values_list method from a QuerySet > in Django; 2) is the arguments for that method; 3) those are the > annotation keys. so 1) is a result of: > qs.values_list('g1', 'g2').annotate(s_v1=Sum('v1'), s_v2=Sum('v2')) > > What i want to have is: > a "big" nested dictionary with 'g1' values as 1st level keys and a > dictionary of aggregates and "subgroups" in it. > > In my example it would be something like this: > { > 1 : { > 's_v1' : 7.0, > 's_v2' : 6.5, > 'g2' :{ > 8 : { > 's_v1' : 5.0, > 's_v2' : 3.5 }, > 9 : { > 's_v1' : 2.0, > 's_v2' : 3.0 } > } > }, > 2 : { > 's_v1' : 6.0, > 's_v2' : 8.0, > 'g2' : { > 8 : { > 's_v1' : 6.0, > 's_v2' : 8.0} > } > }, > ... > } > > # notice the summed values of s_v1 and s_v2 when g1 == 1 > > I was looking for a solution that would let me do that kind of > grouping with variable lists of 2) and 3) i.e. having also 'g3' as > grouping element so the 'g2' dicts could also have their own > "subgroup" and be even more nested then. > I was trying something with itertools.groupby and updating nested > dicts, but as i was writing the code it started to feel too verbose to > me :/ > > Do You have any hints maybe? because i'm kind of stucked :/ > > Regards > > S?awek Not super-efficient, but simple: $ cat python sumover.py cat: python: No such file or directory data = [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 }, { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 }, {'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0}] sum_over = ["s_v1", "s_v2"] group_by = ["g1", "g2"] wanted = { 1 : { 's_v1' : 7.0, 's_v2' : 6.5, 'g2' :{ 8 : { 's_v1' : 5.0, 's_v2' : 3.5 }, 9 : { 's_v1' : 2.0, 's_v2' : 3.0 } } }, 2 : { 's_v1' : 6.0, 's_v2' : 8.0, 'g2' : { 8 : { 's_v1' : 6.0, 's_v2' : 8.0} } }, } def calc(data, group_by, sum_over): tree = {} group_by = group_by + [None] for item in data: d = tree for g in group_by: for so in sum_over: d[so] = d.get(so, 0.0) + item[so] if g: d = d.setdefault(g, {}).setdefault(item[g], {}) return tree got = calc(data, group_by, sum_over)[group_by[0]] assert got == wanted $ python sumover.py $ Untested. From lisaochbarry at gmail.com Sat Feb 5 08:08:12 2011 From: lisaochbarry at gmail.com (Lisa Fritz Barry Griffin) Date: Sat, 5 Feb 2011 05:08:12 -0800 (PST) Subject: Init a dictionary with a empty lists Message-ID: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> Hi there, How can I do this in a one liner: maxCountPerPhraseWordLength = {} for i in range(1,MAX_PHRASES_LENGTH+1): maxCountPerPhraseWordLength[i] = 0 Thanks! From anand.shashwat at gmail.com Sat Feb 5 08:34:40 2011 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 5 Feb 2011 19:04:40 +0530 Subject: Init a dictionary with a empty lists In-Reply-To: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> References: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> Message-ID: On Sat, Feb 5, 2011 at 6:38 PM, Lisa Fritz Barry Griffin < lisaochbarry at gmail.com> wrote: > Hi there, > > How can I do this in a one liner: > > maxCountPerPhraseWordLength = {} > for i in range(1,MAX_PHRASES_LENGTH+1): > maxCountPerPhraseWordLength[i] = 0 > maxCountPerPhraseWordLength = {} [maxCountPerPhraseWordLength.setdefault(i, 0) for i in range(1,MAX_PHRASES_LENGTH+1)] >From setdefaults documentation, 'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D' > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -- ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Feb 5 08:36:41 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 05 Feb 2011 14:36:41 +0100 Subject: Init a dictionary with a empty lists References: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> Message-ID: Lisa Fritz Barry Griffin wrote: > How can I do this in a one liner: > > maxCountPerPhraseWordLength = {} > for i in range(1,MAX_PHRASES_LENGTH+1): > maxCountPerPhraseWordLength[i] = 0 You can init a dictionary with zeroes with d = dict.fromkeys(range(1, MAX_PHRASES_LENGTH+1), 0) but this won't work as expected for mutable values: >>> d = dict.fromkeys(range(5), []) >>> d {0: [], 1: [], 2: [], 3: [], 4: []} >>> d[0].append(42) >>> d {0: [42], 1: [42], 2: [42], 3: [42], 4: [42]} Oops! all values refere to the same list. Instead you can use a defaultdict which adds items as needed: >>> from collections import defaultdict >>> d = defaultdict(list) >>> d defaultdict(, {}) >>> d[0].append(42) >>> d defaultdict(, {0: [42]}) >>> d[7].append(123) >>> d defaultdict(, {0: [42], 7: [123]}) From urban.dani at gmail.com Sat Feb 5 08:38:29 2011 From: urban.dani at gmail.com (Daniel Urban) Date: Sat, 5 Feb 2011 14:38:29 +0100 Subject: Init a dictionary with a empty lists In-Reply-To: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> References: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> Message-ID: On Sat, Feb 5, 2011 at 14:08, Lisa Fritz Barry Griffin wrote: > Hi there, > > How can I do this in a one liner: > > ? ? ? ?maxCountPerPhraseWordLength = {} > ? ? ? ?for i in range(1,MAX_PHRASES_LENGTH+1): > ? ? ? ? ? ?maxCountPerPhraseWordLength[i] = 0 maxCountPerPhraseWordLength = {0 for i in range(1,MAX_PHRASES_LENGTH+1)} But I suggest using a defaultdict: http://docs.python.org/dev/py3k/library/collections#defaultdict-objects Daniel From vlastimil.brom at gmail.com Sat Feb 5 09:05:48 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 5 Feb 2011 15:05:48 +0100 Subject: Init a dictionary with a empty lists In-Reply-To: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> References: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> Message-ID: 2011/2/5 Lisa Fritz Barry Griffin : > Hi there, > > How can I do this in a one liner: > > ? ? ? ?maxCountPerPhraseWordLength = {} > ? ? ? ?for i in range(1,MAX_PHRASES_LENGTH+1): > ? ? ? ? ? ?maxCountPerPhraseWordLength[i] = 0 > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, as has been already suggested, using collections.defaultdict may be appropriate, but it's fairly straightforward to mimic the original code with a generator expression in dict(...) maxCountPerPhraseWordLength = dict((i,0) for i in range(1,MAX_PHRASES_LENGTH+1)) or with a dict literal (in newer python versions) maxCountPerPhraseWordLength = {i:0 for i in range(1,MAX_PHRASES_LENGTH+1)} (possibly using xrange for larger dicts - in pyton 2) hth, vbr From mdekauwe at gmail.com Sat Feb 5 09:37:48 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sat, 5 Feb 2011 06:37:48 -0800 (PST) Subject: code structure advise for a model References: <314af16f-adf2-4d78-88a8-2cb50843d858@a28g2000vbo.googlegroups.com> Message-ID: <51291bdc-c29e-48e6-a30b-1f3afc79d308@o21g2000prn.googlegroups.com> On Feb 4, 8:41?pm, Marco Nawijn wrote: > On Feb 4, 3:43?am, Martin De Kauwe wrote: > > > > > > > Hi, > > > I am translating some c++ code to python and just wanted to ask some > > advise on structure. The original has everything declared globally and > > nothing passed via function (I assume, but don't know, that this isn't > > just standard c++ practice!). So given this, I have a pretty much > > clean slate as I can't quite just copy the functions over. I was > > thinking something like this > > > class Params: > > > ? ? def __init__(self, fname): > > ? ? ? ? self.set_inital_condtions() > > ? ? ? ? self.read_input_file(fname) > > > ? ? def set_inital_conditons(self): > > ? ? ? ? self.some_parm = 0.0 > > > ? ? def read_input_file(fname): > > > ? ? ? ? #read file, change initial params if specified > > > then I thought I could pass this as an object to the model class > > > class Model(Params): > > > ? ? def __init__(self): > > ? ? ? ? # blah > > > ? ? def some_func(self): > > ? ? ? ? ?if (Params.some_param == something): > > ? ? ? ? ? ? ?foo > > > OR this just a very bad way to structure it? > > > The other thing I can't decide on is how to pass the parameters and > > variables through the class. So because of the way the original is > > written (everything is global), I could just inherit things, but it > > does means there is a lot of self. syntax. So I wondered if it might > > be better to pass things as function arguments? Any thoughts? I am > > also half considering other users from non-python backgrounds and what > > might seem very alien (syntax) to them. > > > thanks in advance > > > (ps. I am cross posting this on comp.lang.python as I am not sure > > where is more appropriate). > > I would structure it in three classes/functions: > 1. A parser class/function that reads an input file and returns a > Parameters object > 2. A Parameters class > 3. A Model class that uses the Parameters > > You would end up with something like the following: > > class MyParser(object): > > ? ? def __init__(self, filename=None): > ? ? ? ? self.filename = filename > > ? ? def parse(self, filename): > > ? ? ? ? params = Parameters() > > ? ? ? ? ...read info from filename and update parameters > > ? ? ? ? return params > > class Parameters(object): > > ? ? def __init__(self): > ? ? ? ? ?self.myAttribute1 = 0 > ? ? ? ? ?self.myAttribute2 = "A string" > > class MyModel(object): > > ? ?def __init__(self, parameters): > ? ? ? ?self.parameters = parameters > > ? ?def solve(self): > ? ? ? ? ...solve the problem > > The driver program would look something like this: > > parser = MyParser() > > params = parser.parse('inputfile') > > model = MyModel(params) > model.solve() > > I hope this is helpfull for you. > > Regards, > > Marco thanks for that. I decided to read the params straight into a set of dictionaries and then pass these dictionaries around the various model methods. From steve+comp.lang.python at pearwood.info Sat Feb 5 09:38:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Feb 2011 14:38:36 GMT Subject: Init a dictionary with a empty lists References: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> Message-ID: <4d4d60ec$0$29990$c3e8da3$5496439d@news.astraweb.com> On Sat, 05 Feb 2011 14:38:29 +0100, Daniel Urban wrote: > On Sat, Feb 5, 2011 at 14:08, Lisa Fritz Barry Griffin > wrote: >> Hi there, >> >> How can I do this in a one liner: >> >> ? ? ? ?maxCountPerPhraseWordLength = {} >> ? ? ? ?for i in range(1,MAX_PHRASES_LENGTH+1): >> ? ? ? ? ? ?maxCountPerPhraseWordLength[i] = 0 > > maxCountPerPhraseWordLength = {0 for i in range(1,MAX_PHRASES_LENGTH+1)} Unfortunately not. In versions before Python 2.7, it will give a SyntaxError. In 2.7 or better it gives a set instead of a dict: >>> MAX_PHRASES_LENGTH = 5 >>> maxCountPerPhraseWordLength={0 for i in range(1,MAX_PHRASES_LENGTH+1)} >>> maxCountPerPhraseWordLength set([0]) This will do the job most simply: >>> dict(zip(range(1, MAX_PHRASES_LENGTH+1), [0]*MAX_PHRASES_LENGTH)) {1: 0, 2: 0, 3: 0, 4: 0, 5: 0} Or this: >>> dict((i, 0) for i in range(1, MAX_PHRASES_LENGTH+1)) {1: 0, 2: 0, 3: 0, 4: 0, 5: 0} But perhaps the most simple solution is to just leave the dict empty, and instead of fetching items with dict[i], use dict.get(i, 0) or dict.setdefault(i, 0). -- Steven From xahlee at gmail.com Sat Feb 5 09:53:28 2011 From: xahlee at gmail.com (Xah Lee) Date: Sat, 5 Feb 2011 06:53:28 -0800 (PST) Subject: Guy Steele on Parallel Programing Message-ID: <1ceb145f-018a-4782-a97d-eba9d9d79f6f@y4g2000prh.googlegroups.com> might be interesting. ?Guy Steele on Parallel Programing? http://xahlee.org/comp/Guy_Steele_parallel_computing.html -------------------------------------------------- Guy Steele on Parallel Programing Xah Lee, 2011-02-05 A fascinating talk by the well respected computer scientist Guy Steele. (famously known as one of the author of Scheme Lisp) How to Think about Parallel Programming: Not! (2011-01-14) By Guy Steele. @ http://www.infoq.com/presentations/Thinking-Parallel-Programming The talk is a bit long, at 70 minutes. The first 26 minutes he goes thru 2 computer programs written for 1970's machines. It's quite interesting to see how software on punch card works. For most of us, we never seen a punch card. He actually goes thru it ?line by line?, actually ?hole by hole?. Watching it, it gives you a sense of how computers are like in the 1970s. At 00:27, he starts talking about ?automating resource management?, and quickly to the main point of his talk, as in the title, about what sort of programing paradigms that are good for parallel programing. Here, parallel programing means solving a problem by utilizing multiple CPU or nodes (as in clusters or grid). This is important today, because CPU don't get much faster anymore; instead, each our computer are getting more CPU (multi-core). In the rest 40 min of the talk, he steps thru 2 programs that solves a simple problem of splitting a sentence into words. First program is typical sequential style, using do-loop (accumulator). The second program is written in his language Fortress, using functional style. He then summarizes a few key problems with traditional programing patterns, and introduces a few critical programing patterns that he thinks is critical for programing languages to automate parallel computing. In summary, as a premise, he believes that programers should not worry about parallelism at all, but the programing language should automatically do it. Then, he illustrates that there are few programing patterns that we must stop using, because if you do write your code in such paradigm, then it would be very hard to parallelize the code, either manually or by machine AI. If you are a functional programer and read FP news in the last couple of years, his talk doesn't cover much new. However, i find it very interesting, because: * ? This is the first time i see Guy Steele talk. He talks slightly fast. Very bright guy. * ? The detailed discussion of punch card code on 1970's machine is quite a eye-opener for those of us who's not in that era. * ? You get to see Fortress code, and its use of fancy unicode chars. * ? Thru the latter half of talk, you get a concrete sense of some critical ?do's ? don'ts? in coding paradigms about what makes automated parallel programing possible or impossible. In much of 2000s, i did not understand why compilers couldn't just automatically do parallelism. I thought about it in 2009, and realized why. See: Why Must Software Be Rewritten For Multi-Core Processors?. -------------------- Parallel Computing vs Concurrency Problems Note that parallel programing and concurrency problem are not the same thing. Parallel programing is about writing code that can use multiple CPU. Concurrency problems is about problems of concurrent computations using the same resource or time (e.g. race condition, file locking). See: Parallel computing ? Concurrency (computer science) -------------------- Fortress ? Unicode It's interesting that Fortress language freely uses unicode chars. For example, list delimiters are not the typical {} or [], but the unicode angle bracket ??. (See: Matching Brackets in Unicode.) It also uses the circle plus ? as operator. (See: Math Symbols in Unicode.) I really appreciate such use of unicode. The tradition of sticking to the 95 chars in ASCII of 1960s is extremely limiting. It creates complex problems manifested in: * String Escape mechanism (C's ?\n?, widely adopted.) * Complex delimiters (Python's triple quotes and perl's variable delimiters q() q[] q{} m//, and heredoc. (See: Strings in Perl and Python ? Heredoc mechanism in PHP and Perl.) * Crazy leaning toothpick syndrome, especially bad in emacs regex. * Complexities in character representation (See: Emacs's Key Notations Explained (/r, ^M, C-m, RET, , M-, meta) ? HTML entities problems. See: HTML Entities, Ampersand, Unicode, Semantics.) * URL Percent Encoding problems and complexities: Javascript Encode URL, Escape String All these problems occur because we are jamming so many meanings into about 20 symbols in ASCII. See also: * Computer Language Design: Strings Syntax * HTML6: Your JSON and SXML Simplified Was this page useful to you? Also, almost all of today's languages do not support unicode in function or variable names, so you can forget about using unicode in variable names (e.g. ?=3) or function names (e.g. ?lambda? as ??? or ?function? as ???), or defining your own operators (e.g. ???). (Exceptions i know works well in practice are: Mathematica, Javascript, Java, Emacs Lisp. See: Unicode Support in Ruby, Perl, Python, Emacs Lisp.) Xah ? http://xahlee.org/ From urban.dani at gmail.com Sat Feb 5 10:03:47 2011 From: urban.dani at gmail.com (Daniel Urban) Date: Sat, 5 Feb 2011 16:03:47 +0100 Subject: Init a dictionary with a empty lists In-Reply-To: <4d4d60ec$0$29990$c3e8da3$5496439d@news.astraweb.com> References: <943b677a-0d6f-42ea-b167-96ae48bbda11@k18g2000vbq.googlegroups.com> <4d4d60ec$0$29990$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Feb 5, 2011 at 15:38, Steven D'Aprano wrote: > On Sat, 05 Feb 2011 14:38:29 +0100, Daniel Urban wrote: > >> On Sat, Feb 5, 2011 at 14:08, Lisa Fritz Barry Griffin >> wrote: >>> Hi there, >>> >>> How can I do this in a one liner: >>> >>> ? ? ? ?maxCountPerPhraseWordLength = {} >>> ? ? ? ?for i in range(1,MAX_PHRASES_LENGTH+1): >>> ? ? ? ? ? ?maxCountPerPhraseWordLength[i] = 0 >> >> maxCountPerPhraseWordLength = {0 for i in range(1,MAX_PHRASES_LENGTH+1)} > > Unfortunately not. In versions before Python 2.7, it will give a > SyntaxError. In 2.7 or better it gives a set instead of a dict: Yeah, sorry, that should have been {i: 0 for i in range(1,MAX_PHRASES_LENGTH+1)} Daniel From glicerinu at gmail.com Sat Feb 5 11:47:05 2011 From: glicerinu at gmail.com (Marc Aymerich) Date: Sat, 5 Feb 2011 08:47:05 -0800 (PST) Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> <7ee6a8c0-4051-4f46-83f3-1c192052311a@d2g2000yqn.googlegroups.com> Message-ID: <82469e8d-7874-4100-8f93-197bedcbae12@y4g2000prh.googlegroups.com> On Feb 5, 1:06?pm, Marc Aymerich wrote: > Thank you all for the answers! > > I'll try to give you the context in which I need to generate classes > like this. > > I'm developing a reusable control panel for an ISP. I have several > modules (VirtualUser, SystemUser, VPS, VirtualHost, ...) and they all > share the fact that you can have limits on resource consumption. for > example. > > VPS: has limits on swap, memory, cpu and disk. > SystemUser: has limits on disk and traffic. > > As all modules share this property of being limited I have decided to > split the limit functionality in a separate module (called resources). > Resources are associated dinamically with (vps, systemuser ...) > through a Monitor class. So it's up to you decide what limits you are > interested to put in the VPS or in the SystemUser ... > > So when you attach the "disk limit" to SystemUser model is necessary > to create a web form for SystemUser a bit different than if you decide > to have disk and traffic limits. That is what my posted code is > supposed to do. > > Do you think that I am on the wrong way designing the control panel > like this? > > Btw, I've seen several interesting ideas to create the class > dinamically (with class factorys, MetaClass, dictionaries ..), but I > have not yet clear whether this will be usefull for create the > __init__ function at runtime too. Any clue on this? > this seems to work :) def makeLimitForm(name, monitors, _model): class Meta: model = _model dct = { 'Meta': Meta } for monitor in monitors: field_name = monitor.resource + "_limit" dct[field_name] = forms.CharField(max_length=100, initial=monitor.default_limit) def __init__(self, *args, **kwargs): ModelForm.__init__(self, *args, **kwargs) if 'instance' in kwargs: for monitor in monitors: field_name = monitor.resource + "_limit" print monitor self.fields[field_name].initial = kwargs['instance'].monitoring.filter(monitor=monitor)[0].current dct['__init__'] = __init__ return type(name,(ModelForm,),dct) From python at mrabarnett.plus.com Sat Feb 5 11:55:06 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 05 Feb 2011 16:55:06 +0000 Subject: IDLE: A cornicopia of mediocrity and obfuscation. In-Reply-To: <2978ccbc-d40f-49e5-a8b7-516064985b88@i14g2000prm.googlegroups.com> References: <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> <2978ccbc-d40f-49e5-a8b7-516064985b88@i14g2000prm.googlegroups.com> Message-ID: <4D4D80EA.3080305@mrabarnett.plus.com> On 05/02/2011 09:44, flebber wrote: > On Feb 5, 10:24 am, Stephen Hansen wrote: >> On 2/4/11 3:01 PM, rantingrick wrote: >> >>>> Put your money where your mouth is. >> >>> ditto! >> >> I thought as much. >> >> My money is where my mouth is: but that is not IDLE, as I have no use >> for it and no interest in it at all. The status quo with regards to IDLE >> is satisfactory to me. >> >> You're the one talking so much about how it needs to improve. So do it. >> Get started. Now. >> >> But you'll just find another excuse to rant on like you always do, and >> be basically useless. >> >> Me, I _have_ contributed patches: I have released actual code that >> actual people have found actually useful. I do run two build slaves and >> proactively try to assist in resolving issues that come up with Python's >> testing (usually: ouch, there's a lot of red at the moment, must get >> cracking) and stability. >> >> So, yeah. You're the hypocrite here, man. >> >> -- >> >> Stephen Hansen >> ... Also: Ixokai >> ... Mail: me+list/python (AT) ixokai (DOT) io >> ... Blog:http://meh.ixokai.io/ >> >> signature.asc >> < 1KViewDownload > > Idlefork isn't dead to rick! just pining for the alps! "alps"? That should be "fjords"! :-) From sigzero at gmail.com Sat Feb 5 12:07:41 2011 From: sigzero at gmail.com (Robert) Date: Sat, 5 Feb 2011 12:07:41 -0500 Subject: IDLE: A cornicopia of mediocrity and obfuscation. References: <1df3abde-43f1-4dd9-92d3-ad5c00fbb223@8g2000prt.googlegroups.com> <3c6745d4-686c-45c7-9011-86882b806d06@r4g2000vbq.googlegroups.com> <1fbf7815-ea63-4322-889d-4b15fc66bb25@z20g2000yqe.googlegroups.com> <1daeb81f-f004-4111-9ddc-0acb2b01b5f6@x13g2000vbe.googlegroups.com> <7754ab65-0184-4125-b04a-ede5e88c35f5@w7g2000pre.googlegroups.com> <69cef019-5ae0-41bb-8263-6b2f7e23573c@f30g2000yqa.googlegroups.com> Message-ID: On 2011-02-04 13:34:42 -0500, rantingrick said: > > I don't care who *that* person is as long as *they* are willing to > push IDLE forward. I would be honored to accept the reigns and lead OR > follow someone else's lead. But we need to receive the old idlefork or > have them delete the old idle fork as too much confusion will spread > with when two idleforks exists. There is a movement afoot to update IDLE. I am going to be a part of that. There is an implementation called VIDLE that made some changes and those are going to be integrated in before the major refactorings begin. This initial push will hit both 2.7.x (I think I read it right) and 3.x lines. Going forward though we are going to focus on IDLE in the 3.x series only. There is a nice list of changes and some folks that are willing to help when the repo goes into Mercurial. -- Robert From miki.tebeka at gmail.com Sat Feb 5 12:49:52 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 5 Feb 2011 09:49:52 -0800 (PST) Subject: Create classes at runtnime In-Reply-To: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> Message-ID: > I need to create a pretty complex class at runtime. You can take the approach that namedtuple does and create a python code for the class as string and then exec it. See http://svn.python.org/view/python/trunk/Lib/collections.py?view=markup HTH, -- Miki http://pythonwise.blogspot.com From me+list/python at ixokai.io Sat Feb 5 13:17:58 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 05 Feb 2011 10:17:58 -0800 Subject: Unable to register com component built with python2.7 In-Reply-To: <262cf3dd-031b-49a6-a483-8da4bf26cb51@o18g2000prh.googlegroups.com> References: <262cf3dd-031b-49a6-a483-8da4bf26cb51@o18g2000prh.googlegroups.com> Message-ID: <4D4D9456.9080005@ixokai.io> On 2/5/11 2:33 AM, sniffer wrote: > Hi all, > I have built a com component using python2.7 on win 7 but the > component refuses to register ,every time i try to register it says > the specified module could not be found unable to load python.dll ,i > also tried building the same com server with python2.7 again on a win- > xp system but to no avail ,i even tried building and registring the > com server after removing all imports and just leaving 1 function > which returns nothing but the string "hello world" any pointers would > be great It sounds like your Python install directory (C:\Python27 probably) is not on your PATH. Which is the default. There's much debate about that on and off, but in short-- if you go add it to your environment variables things will probably work. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From rui.maciel at gmail.com Sat Feb 5 14:11:59 2011 From: rui.maciel at gmail.com (Rui Maciel) Date: Sat, 05 Feb 2011 19:11:59 +0000 Subject: Guy Steele on Parallel Programing References: <1ceb145f-018a-4782-a97d-eba9d9d79f6f@y4g2000prh.googlegroups.com> Message-ID: <4d4da0fd$0$12285$a729d347@news.telepac.pt> Xah Lee wrote: > might be interesting. > > ?Guy Steele on Parallel Programing? > http://xahlee.org/comp/Guy_Steele_parallel_computing.html Very interesting. Thanks for the link. Rui Maciel From nick at fly.srk.fer.hr Sat Feb 5 14:30:55 2011 From: nick at fly.srk.fer.hr (Nikola Skoric) Date: Sat, 5 Feb 2011 19:30:55 +0000 (UTC) Subject: sending through non-default gateway Message-ID: Is there a way to create a TCP connection using a gateway of my choice? I have a regular user account on a WinXP machine. It has a DNS server and default gateway configured, and that DNS server and default gateway don't see the rest of the Internet, just the local network. But, I know an IP address of another DNS/gateway pair which is used to access the Internet, and I can ping them (and send nslookup queries) from my machine. So, is there a way to tell python "don't use my default gateway, here is an address of the gateway I want you to use"? I've been googling, but to no avail... -- "Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams" From drsalists at gmail.com Sat Feb 5 17:13:11 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 5 Feb 2011 14:13:11 -0800 Subject: sending through non-default gateway In-Reply-To: References: Message-ID: IIRC, this is an instance of what's called "source routing", and was largely shut off after network admins realized it was a security issue. Of course, if you have root/administrator permission, you could probably do it. But if you have that, you could probably just fix the routing table. On Sat, Feb 5, 2011 at 11:30 AM, Nikola Skoric wrote: > Is there a way to create a TCP connection using a gateway of my > choice? > > I have a regular user account on a WinXP machine. It has a DNS server > and default gateway configured, and that DNS server and default > gateway don't see the rest of the Internet, just the local > network. But, I know an IP address of another DNS/gateway pair which > is used to access the Internet, and I can ping them (and send nslookup > queries) from my machine. > > So, is there a way to tell python "don't use my default gateway, here > is an address of the gateway I want you to use"? I've been googling, > but to no avail... > > -- > "Now the storm has passed over me > I'm left to drift on a dead calm sea > And watch her forever through the cracks in the beams > Nailed across the doorways of the bedrooms of my dreams" > -- > http://mail.python.org/mailman/listinfo/python-list > From kwa at kuwata-lab.com Sat Feb 5 17:25:46 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sun, 6 Feb 2011 07:25:46 +0900 Subject: Oktest 0.7.0 released - a new-style testing library Message-ID: I released Oktest 0.7.0. http://pypi.python.org/pypi/Oktest/ http://packages.python.org/Oktest/ Oktest is a new-style testing library for Python. :: from oktest import ok ok (x) > 0 # same as assert_(x > 0) ok (s) == 'foo' # same as assertEqual(s, 'foo') ok (s) != 'foo' # same as assertNotEqual(s, 'foo') ok (f).raises(ValueError) # same as assertRaises(ValueError, f) ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', unicode)) not_ok (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', int)) ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt')) not_ok ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt')) See http://packages.python.org/Oktest/ for details. NOTICE!! Oktest is a young project and specification may change in the future. Enhancements and Changes ------------------------ * enhanced to allow users to define custom assertion functions. :: import oktest from oktest import ok # @oktest.assertion def startswith(self, arg): boolean = self.target.startswith(arg) if boolean == self.expected: return True self.failed("%r.startswith(%r) : failed." % (self.target, arg)) # ok ("Sasaki").startswith("Sas") * rename 'ok().hasattr()' to 'ok().has_attr()'. (but old name is also available for backward compatibility.) * change 'chdir()' to take a function as 2nd argument. :: def f(): ... do_something ... chdir('build', f) # The above is same as: with chdir('build'): ... do_something ... * add document of 'oktest.helper.dummy_io()'. :: with dummy_io("SOS") as io: assert sys.stdin.read() == "SOS" print("Haruhi") assert io.stdout == "Haruhi\n" assert io.stderr == "" * fix 'oktest.tracer.Call#__repr__()' to change output according to whether '==' is called or not. This is aimed to make output of 'ok(tr[0]) == [...]' to be more readable. * change 'Runner#run()' to skip AssertionError if it is raised by 'assert ....' and not 'ok() == ...'. * fix example code for some helper functions. -- regards, makoto kuwata From kb1pkl at aim.com Sat Feb 5 18:29:40 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sat, 05 Feb 2011 18:29:40 -0500 Subject: psd estimation no matplotlib In-Reply-To: References: Message-ID: <4D4DDD64.60802@aim.com> On 02/05/2011 05:19 AM, Jack Yu wrote: > Hi all, > Is there a function psd() for estimating power spectral density that is not > dependent on the importing of matplotlib or pylab [snip] > There is not built into Python, but you could rip the function right out of pylab's or matplotlib's source and put it in your own code, or even just write it yourself. ~Corey From iaoua.iaoua at gmail.com Sat Feb 5 20:34:41 2011 From: iaoua.iaoua at gmail.com (iaoua iaoua) Date: Sat, 5 Feb 2011 17:34:41 -0800 (PST) Subject: Fully functioning email client in Python Message-ID: <7d75973e-8061-4da2-b265-3c18f19b8040@u3g2000vbe.googlegroups.com> Hi all, I'm a complete newbie to this newsgroup and to Python (pretty much) so please be nice and give me a warm welcome. First of all please allow me to properly introduce myself. My name is James Christian and I am a PhD student at the University of Essex in England doing research on Machine Translation. You can see my minimalist homepage at http://privatewww.essex.ac.uk/~jcread Aside from machine translation I also have other AI related research interests that have led me to seek the wisom of Python users and developers on this newsgroup. In a nutshell my problem is this. I have developed an intelligent conversational agent which dialogues with a user to find out what they are really searching for. The domain is open and helps the user find which businesses/websites offer the services or products the user is looking for according to needs elicited from the user during the dialogue. I have small but growing base of experimental users who want to access the agent via email (the agent can be quite slow at times due to the complexity of the system) so that they can ask questions and forget about them until an answer comes to their inbox. And so I need to extend my agent so that it can receive and send emails and extract the relevant text answers to questions from the user. This requires full threading capabilities and automatic text extraction of only the new and relevant material (minus signatures of course). Now, I'm not completely lazy and so I have already done a little homework. I've been reading O'Reilly's Programming Python and Foundations of Python Network Programming which have both been very helpful in ascertaining that Python is a strong candidate solution. Both books talk about the email (for message and header construction and parsing) sendmail (for sending mail via SMTP) and poplib (for receiving mail with POP3) libraries. However, as you can imagine I already really quite have my work cut out with maintaining and expanding the dialogue of the system and with the research on Machine Translation. What I really need is a ready made fully functional Python client that already has it that offers me a simple interface to extract text from received messages along with a message id that I can use to associate the response to a question with and allows me to send out new questions or answers along with a message id I can use to track future responses with. I need something that already has the whole shebang. Can support POP3, IMAP, SSL authentication, message threading etc. Can anyone point to something that will save me the effort of building this thing from scratch and first principles? Thanks in advance for any useful suggestions. James Christian From adi at lspl.net Sat Feb 5 22:47:16 2011 From: adi at lspl.net (sniffer) Date: Sat, 5 Feb 2011 19:47:16 -0800 (PST) Subject: Unable to register com component built with python2.7 In-Reply-To: Message-ID: Stephen thanks for your reply but my python installation directory is in my path any other pointers From adi at lspl.net Sat Feb 5 22:47:16 2011 From: adi at lspl.net (sniffer) Date: Sat, 5 Feb 2011 19:47:16 -0800 (PST) Subject: Unable to register com component built with python2.7 In-Reply-To: Message-ID: Stephen thanks for your reply but my python installation directory is in my path any other pointers From kb1pkl at aim.com Sat Feb 5 23:14:38 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Sat, 05 Feb 2011 23:14:38 -0500 Subject: P2PU Python Challenges Message-ID: <4D4E202E.3000902@aim.com> In my journeys across the face of the Internet, I found this: http://p2pu.org/general/python-challenges Not sure what it's really going to be, but any new programmers/people looking for something to do might be interested. I'm not quite sure how a class can be organised around a web riddle, but it's there so someone must have figured it out. Just thought I'd share. From nick at fly.srk.fer.hr Sun Feb 6 01:10:59 2011 From: nick at fly.srk.fer.hr (Nikola Skoric) Date: Sun, 6 Feb 2011 06:10:59 +0000 (UTC) Subject: sending through non-default gateway References: Message-ID: Dana Sat, 5 Feb 2011 14:13:11 -0800, Dan Stromberg kaze: > IIRC, this is an instance of what's called "source routing", and was > largely shut off after network admins realized it was a security > issue. > > Of course, if you have root/administrator permission, you could > probably do it. But if you have that, you could probably just fix the > routing table. Yeah, I don't have admin priviledges, it's my office computer which is supposed to be cut of the Internet. I did a bit of reading on source routing and I'd like to try it. Just for fun, in case our router accepts such packets. So, is there a way to do it in python? -- "Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams" From shrvtsnvs at gmail.com Sun Feb 6 03:58:54 2011 From: shrvtsnvs at gmail.com (Shrivats) Date: Sun, 6 Feb 2011 14:28:54 +0530 Subject: [Tutor] P2PU Python Challenges In-Reply-To: <4D4E202E.3000902@aim.com> References: <4D4E202E.3000902@aim.com> Message-ID: <20110206085854.GA2997@zorander> On Sat, Feb 05, 2011 at 11:14:38PM -0500, Corey Richardson wrote: > In my journeys across the face of the Internet, I found this: > http://p2pu.org/general/python-challenges > Browsing that site a little more, I also saw this - "Learn Python the hard way". I'm not sure how useful that would be, most of the exercises are geared towards fixing bugs as they come up. Maybe some newbie might find it useful to see how to go about fixing bugs. :) Regards, Shrivats From __peter__ at web.de Sun Feb 6 07:31:16 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 06 Feb 2011 13:31:16 +0100 Subject: Create classes at runtnime References: <00b80434-8f3a-4a38-a633-baa183bd0221@q2g2000pre.googlegroups.com> <7ee6a8c0-4051-4f46-83f3-1c192052311a@d2g2000yqn.googlegroups.com> <82469e8d-7874-4100-8f93-197bedcbae12@y4g2000prh.googlegroups.com> Message-ID: Marc Aymerich wrote: > On Feb 5, 1:06 pm, Marc Aymerich wrote: >> Thank you all for the answers! >> >> I'll try to give you the context in which I need to generate classes >> like this. >> >> I'm developing a reusable control panel for an ISP. I have several >> modules (VirtualUser, SystemUser, VPS, VirtualHost, ...) and they all >> share the fact that you can have limits on resource consumption. for >> example. >> >> VPS: has limits on swap, memory, cpu and disk. >> SystemUser: has limits on disk and traffic. >> >> As all modules share this property of being limited I have decided to >> split the limit functionality in a separate module (called resources). >> Resources are associated dinamically with (vps, systemuser ...) >> through a Monitor class. So it's up to you decide what limits you are >> interested to put in the VPS or in the SystemUser ... >> >> So when you attach the "disk limit" to SystemUser model is necessary >> to create a web form for SystemUser a bit different than if you decide >> to have disk and traffic limits. That is what my posted code is >> supposed to do. >> >> Do you think that I am on the wrong way designing the control panel >> like this? >> >> Btw, I've seen several interesting ideas to create the class >> dinamically (with class factorys, MetaClass, dictionaries ..), but I >> have not yet clear whether this will be usefull for create the >> __init__ function at runtime too. Any clue on this? >> > > this seems to work :) > > def makeLimitForm(name, monitors, _model): > > class Meta: > model = _model > dct = { 'Meta': Meta } > > for monitor in monitors: > field_name = monitor.resource + "_limit" > dct[field_name] = forms.CharField(max_length=100, > initial=monitor.default_limit) > > def __init__(self, *args, **kwargs): > ModelForm.__init__(self, *args, **kwargs) > if 'instance' in kwargs: > for monitor in monitors: > field_name = monitor.resource + "_limit" > print monitor > self.fields[field_name].initial = > kwargs['instance'].monitoring.filter(monitor=monitor)[0].current > > dct['__init__'] = __init__ > > return type(name,(ModelForm,),dct) I've looked around to see whether Django offers an API for your usecase, but only found http://code.djangoproject.com/wiki/DynamicModels which seems to describe what you are already doing. From eggheadcafe at anjum.otherinbox.com Sun Feb 6 09:41:35 2011 From: eggheadcafe at anjum.otherinbox.com (Anjum Naseer) Date: Sun, 06 Feb 2011 14:41:35 GMT Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> Message-ID: <20112694118usenet@eggheadcafe.com> You may be interested in a little Python module I wrote to make handling of command line arguments even easier (open source and free to use) - http://freshmeat.net/projects/commando > On Wednesday, June 02, 2010 12:37 AM Michele Simionato wrote: > I would like to announce to the world the first public release of > plac: > > http://pypi.python.org/pypi/plac > > Plac is a wrapper over argparse and works in all versions of > Python starting from Python 2.3 up to Python 3.1. > > With blatant immodesty, plac claims to be the easiest to use command > line arguments parser module in the Python world. Its goal is to > reduce the > learning curve of argparse from hours to minutes. It does so by > removing the need to build a command line arguments parser by hand: > actually it is smart enough to infer the parser from function > annotations. > > Here is a simple example (in Python 3) to wet your appetite: > > $ cat example.py > def main(arg: "required argument"): > "do something with arg" > print('Got %s' % arg) > > if __name__ == '__main__': > import plac; plac.call(main) # passes sys.argv[1:] to main > > $ python example.py -h > usage: example.py [-h] arg > > do something with arg > > positional arguments: > arg required argument > > optional arguments: > -h, --help show this help message and exit > > > $ python example.py > usage: example.py [-h] arg > example.py: error: too few arguments > > $ python example.py arg > Got arg > > $ python example.py arg1 arg2 > usage: example.py [-h] arg > example.py: error: unrecognized arguments: arg2 > > You can find in the documentation a lot of other simple and not so > simple > examples: > > http://micheles.googlecode.com/hg/plac/doc/plac.html > > > Enjoy! > > Michele Simionato > > P.S. answering an unspoken question: yes, we really needed yet > another > command line arguments parser! ;) >> On Wednesday, June 02, 2010 4:28 AM Tim Golden wrote: >> On 02/06/2010 05:37, Michele Simionato wrote: >> >> I like it. I am a constant user of the >> >> def main (a, b=1, c=2): >> >> if __name__ == '__main__': >> main (*sys.argv[1:]) >> >> pattern, which provides a minimally semi-self-documenting >> approach for positional args, but I have always found the existing >> offerings just a little too much work to bother with. >> I will give plac a run and see how it behaves. >> >> Thanks >> >> TJG >>> On Wednesday, June 02, 2010 4:43 AM Paul Rubin wrote: >>> Tim Golden writes: >>> >>> After using optparse a couple of times I got the hang of it. Maybe its >>> docs could be organized a bit better, but it does the obvious things >>> conveniently once you have figured it out a bit. >>>> On Wednesday, June 02, 2010 4:49 AM Michele Simionato wrote: >>>> Notice that optparse is basically useless in the use case Tim is >>>> considering (positional arguments) since it only manages options. >>>>> On Wednesday, June 02, 2010 4:52 AM Jean-Michel Pichavant wrote: >>>>> Michele Simionato wrote: >>>>> Thanks for participating. >>>>> >>>>> JM >>>>>> On Wednesday, June 02, 2010 5:01 AM Stefan Behnel wrote: >>>>>> Paul Rubin, 02.06.2010 10:43: >>>>>> >>>>>> Same from here. I managed to talk a Java-drilled collegue of mine into >>>>>> writing a Python script for a little command line utility, but he needed a >>>>>> way to organise his argument extraction code when the number of arguments >>>>>> started to grow beyond two. I told him that there were two ways to do it: >>>>>> do it by hand or do it right. He took the right choice and I took him to >>>>>> the optparse docs, copied the first example into his code and we adapted it >>>>>> a little. He just loved the beauty of it. >>>>>> >>>>>> Stefan >>>>>>> On Wednesday, June 02, 2010 5:14 AM Michele Simionato wrote: >>>>>>> a >>>>>>> it >>>>>>> >>>>>>> Could you show plac to your friend? I would be curious to know what he >>>>>>> think. >>>>>>> Perhaps he would call out his judgment on optparse ;) >>>>>>>> On Wednesday, June 02, 2010 6:42 AM Antoine Pitrou wrote: >>>>>>>> By the way, could you stop naming these "optional arguments", since >>>>>>>> positional arguments can be optional as well? It is confusing :) >>>>>>>> >>>>>>>> Thanks >>>>>>>> >>>>>>>> Antoine. >>>>>>>>> On Wednesday, June 02, 2010 6:51 AM Tim Golden wrote: >>>>>>>>> On 02/06/2010 11:42, Antoine Pitrou wrote: >>>>>>>>> >>>>>>>>> The great thing with English is that you can use nouns as >>>>>>>>> adjectives without changing them, so you can say "option arguments" >>>>>>>>> and "position arguments" quite happily here :) >>>>>>>>> >>>>>>>>> But then you run into the fact that you are having semantic arguments >>>>>>>>> about argument semantics :( >>>>>>>>> >>>>>>>>> TJG >>>>>>>>>> On Wednesday, June 02, 2010 9:06 AM J. Cliff Dyer wrote: >>>>>>>>>> +1 >>>>>>>>>> >>>>>>>>>> Options are options, arguments are arguments. An optional argument is >>>>>>>>>> not an option. It is an argument that can be left out. >>>>>>>>>>> On Wednesday, June 02, 2010 9:46 AM Michele Simionato wrote: >>>>>>>>>>> wrote: >>>>>>>>>>> >>>>>>>>>>> It seems I have to take that claim back. A few hours after the >>>>>>>>>>> announce I was pointed out to http://pypi.python.org/pypi/CLIArgs >>>>>>>>>>> which, I must concede, is even easier to use than plac. It seems >>>>>>>>>>> everybody has written its own command line arguments parser! >>>>>>>>>>>> On Wednesday, June 02, 2010 8:51 PM alex23 wrote: >>>>>>>>>>>> I think I still find opterator[1] to be simpler and clearer. No magic >>>>>>>>>>>> global variables, no spooky behaviour with the main function, just a >>>>>>>>>>>> decorator and docstring. >>>>>>>>>>>> >>>>>>>>>>>> 1: http://github.com/buchuki/opterator >>>>>>>>>>>>> On Thursday, June 03, 2010 11:28 PM Michele Simionato wrote: >>>>>>>>>>>>> wrote: >>>>>>>>>>>>> >>>>>>>>>>>>> The second release is out. I have added the recognition of keyword >>>>>>>>>>>>> arguments, improved the formatting of the help message, and added many >>>>>>>>>>>>> tests. >>>>>>>>>>>>>> On Friday, June 04, 2010 8:48 PM Kenny Meyer wrote: >>>>>>>>>>>>>> wrote: >>>>>>>>>>>>>> >>>>>>>>>>>>>> I like this approach to command-line argument parsing! Thanks for >>>>>>>>>>>>>> sharing your work. >>>>>>>>>>>>>> Submitted via EggHeadCafe >>>>>>>>>>>>>> WCF Generic DataContract object Serializer >>>>>>>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/59ae2b9e-a3be-4cd5-a0ef-939a7abbdc3a/wcf-generic-datacontract-object-serializer.aspx From eggheadcafe at anjum.otherinbox.com Sun Feb 6 09:45:01 2011 From: eggheadcafe at anjum.otherinbox.com (Anjum Naseer) Date: Sun, 06 Feb 2011 14:45:01 GMT Subject: Ideas for a module to process command line arguments Message-ID: <20112694444usenet@eggheadcafe.com> You may be interested in a little Python module I wrote to make handling of command line arguments even easier (open source and free to use) - http://freshmeat.net/projects/commando > On Tuesday, January 11, 2011 12:18 AM Sohail wrote: > Hey, every body has their own favorite method/ways to process command line arguments. I have worked on a little CPython extension to handle command line arguments may be you will find it interesting and useful.... > > To download the source code.... > http://www.stupidcomputing.com/page.php?id=argsv > > Thank you. >> On Tuesday, January 11, 2011 2:25 AM Alice_Bevan?McGregor wrote: >> On 2011-01-10 21:18:41 -0800, Sohail said: >> >> >> Even I have implemented my own way to handle command-line scripts, marrow.script: >> >> https://github.com/pulp/marrow.script >> >> The idea with mine that you write a Python function... and that is it. >> The latest version has experimental support for class-based >> "subcommand" dispatch, but it needs work, needs to be updated to >> support sub-sub commands, and the help text generator needs to be >> overhauled to support classes properly. >> >> The argument list, typecasting, etc. is built from the argspec. Help >> text is pulled from the docstring. Decorators are provided to override >> short names, define explicit callbacks or typecasting functions, etc. >> >> I got tired of using PasteScript and OptParse. Mostly OptParse, actually. :/ >> >> - Alice. >>> On Tuesday, January 11, 2011 3:32 AM Michele Simionato wrote: >>> explicit callbacks or typecasting functions, etc. >>> ly. =A0:/ >>> >>> >>> it is a pity that the argument parsing modules in the standard library >>> are so verbose that everybody is reinventing the same thing :-( It >>> looks like you have reinvented plac: http://pypi.python.org/pypi/plac >>>> On Tuesday, January 11, 2011 9:37 AM Alice_Bevan?McGregor wrote: >>>> On 2011-01-11 00:32:32 -0800, Michele Simionato said: >>>> >>>> And a package called `commandline`. There are many command line >>>> parsing modules, many of which are unmaintained, few have reached 1.0. >>>> >>>> My criteria for 1.0? 100% unit test coverage, complete documentation, >>>> compatibility with 2.6+ and 3.1+ within a single package. >>>> marrow.script meets that criteria, do the others? :) >>>> >>>> - Alice. >>>>> On Tuesday, January 11, 2011 10:06 AM Alice_Bevan?McGregor wrote: >>>>> On 2011-01-11 00:32:32 -0800, Michele Simionato said: >>>>> >>>>> After looking into it, Plac's default help display is not very helpful; >>>>> you need to massage your application a fair amount before generating >>>>> nice, complete-looking argument lists and such. For example: >>>>> >>>>> def main(verbose: ('prints more info', 'flag', 'v'), dsn: 'connection >>>>> string'): >>>>> >>>>> @annotate(dsn="connection string", verbose="prints more info") >>>>> def main(dsn, verbose=False): >>>>> >>>>> The latter is marrow.script, and even without the annotation a more >>>>> complete help text is generated. The -v and flag nature are assumed >>>>> from the first unique character and default value. (Flags, when >>>>> present on the command line, invert the default value.) Py3k >>>>> annotations have not been implemented yet, though. >>>>> >>>>> Also included is an easy way to simulte command-line execution (i.e. by >>>>> reading arguments passed by hand and by returning the exit code, vs. >>>>> reading sys.argv and calling sys.exit()) for unit testing purposes. >>>>> Plac appears (from the documentation) to be written on top of argparse. >>>>> >>>>> - Alice. >>>>>> On Tuesday, January 11, 2011 10:49 AM Michele Simionato wrote: >>>>>> And the problem with that being what? >>>>>>> On Tuesday, January 11, 2011 11:22 AM Jean-Michel Pichavant wrote: >>>>>>> Michele Simionato wrote: >>>>>>> ... not available to python 2.5 / 2.6 users :) >>>>>>> >>>>>>> JM >>>>>>>> On Tuesday, January 11, 2011 11:26 AM Michele Simionato wrote: >>>>>>>> wrote: >>>>>>>> . >>>>>>>> >>>>>>>> In that case easy_install/pip/whatever will install the dependency >>>>>>>> automatically (who is installing >>>>>>>> dependencies by hand nowadays?). More seriously I thought being based >>>>>>>> on a solid module which is >>>>>>>> also part of the standard library (for Python 2.7+) was an asset of >>>>>>>> plac. >>>>>>>>> On Tuesday, January 11, 2011 12:57 PM Mike wrote: >>>>>>>>> wrote: >>>>>>>>> >>>>>>>>> I do. Is this bad? :} >>>>>>>>>> On Wednesday, January 12, 2011 12:41 AM Michele Simionato wrote: >>>>>>>>>> 'connection >>>>>>>>>> re info") >>>>>>>>>> >>>>>>>>>> Honestly I do not see any significant difference both in the >>>>>>>>>> level of verbosity for the annotations and in the quality of the help >>>>>>>>>> message provided in the absence of annotations. Originally plac too >>>>>>>>>> was able to recognize flags automatically by looking at the default >>>>>>>>>> value (if the default value is a boolean then the option is a flag); >>>>>>>>>> however I removed that functionality because I wanted to be able to >>>>>>>>>> differentiate between flag and (smart) options (see >>>>>>>>>> http://micheles.googlecode.com/hg/plac/doc/plac.html#scripts-with-options-a= >>>>>>>>>> nd-smart-options). >>>>>>>>>>> On Wednesday, January 12, 2011 12:43 AM Michele Simionato wrote: >>>>>>>>>>> You are simply spending more time than needed, since there are already >>>>>>>>>>> tools available to perform the task for you. >>>>>>>>>>>> On Wednesday, January 12, 2011 12:09 PM Alice_Bevan?McGregor wrote: >>>>>>>>>>>> On 2011-01-11 21:41:24 -0800, Michele Simionato said: >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Not >>>>>>>>>>>> entirely sure what you mean by 'smart' options. If your'e referring to >>>>>>>>>>>> using a single hyphen and a list of characters to represent a long >>>>>>>>>>>> option (which, to the rest of the world, use two leading hyphens) then >>>>>>>>>>>> that is pretty weird. ;) >>>>>>>>>>>> >>>>>>>>>>>> Consider most of the GNU tools: >>>>>>>>>>>> >>>>>>>>>>>> ls -lvh >>>>>>>>>>>> tar -xzvf file.tgz (goes so far as to make the leading hyphen optional!) >>>>>>>>>>>> less -ceF logfile >>>>>>>>>>>> bc -qw >>>>>>>>>>>> ps -aux (same as tar) >>>>>>>>>>>> >>>>>>>>>>>> And even third-party tools: >>>>>>>>>>>> >>>>>>>>>>>> mysql -fH >>>>>>>>>>>> pg_dump -abO ... >>>>>>>>>>>> >>>>>>>>>>>> One major system in the world that does not really differentiate between >>>>>>>>>>>> long and short options is... DOS, and by extension, Windows. But they >>>>>>>>>>>> also use / as a switch character. >>>>>>>>>>>> >>>>>>>>>>>> Anyway; I am happy with what I have wrought (and am continuing to update >>>>>>>>>>>> with support for class-based sub-command dispatch) and will be >>>>>>>>>>>> utilizing it for all scripts in the Marrow suite. To each their own, >>>>>>>>>>>> but reinvention itself can be for motivations other than NIH. I wanted >>>>>>>>>>>> something pure-Python, portable across the 3k barrier without code >>>>>>>>>>>> modification (no 2to3), that did not use optparse, getopt, or argparse >>>>>>>>>>>> and basically be a translation layer. It can be simpler than that, as >>>>>>>>>>>> marrow.script demonstrates. >>>>>>>>>>>> >>>>>>>>>>>> - Alice. >>>>>>>>>>>>> On Thursday, January 13, 2011 3:32 AM Michele Simionato wrote: >>>>>>>>>>>>> Yes, and plac (it is argparse actually) can accomodate >>>>>>>>>>>>> the Windows convention by setting the prefix_chars to "/". I wanted to >>>>>>>>>>>>> be >>>>>>>>>>>>> able to give that freedom even if personally am more used to the GNU >>>>>>>>>>>>> double-dash >>>>>>>>>>>>> convention. >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> No arguing against that. BTW, I was not criticizing marrow.script, I >>>>>>>>>>>>> was simply >>>>>>>>>>>>> deploring the situation in the standard library. If the same approach >>>>>>>>>>>>> for parsing >>>>>>>>>>>>> command-line options is being reinvented by different people multiple >>>>>>>>>>>>> times there >>>>>>>>>>>>> must be something wrong with the current standard. >>>>>>>>>>>>> Submitted via EggHeadCafe >>>>>>>>>>>>> SQL Server Best Practices >>>>>>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/56efb426-550b-48cc-b52a-eca25b6cd427/sql-server-best-practices.aspx From aahz at pythoncraft.com Sun Feb 6 09:53:20 2011 From: aahz at pythoncraft.com (Aahz) Date: 6 Feb 2011 06:53:20 -0800 Subject: Multiple independently started python processes and sharing of a module References: Message-ID: In article , Martin P. Hellwig wrote: > >Currently my solution is to wrap the module around a module that when >used creates a directory and pipes to the process >(multiprocessing.Connection) thus enforcing single access and within >that I have wrapped the db function around again so that select >statement as mentioned above is actually an execute followed by a fetchall. > >I still have the nagging feeling that I have reinvented a squared wheel >or am totally missing the point. What you want is a worker pool or connection pool. I.e. you keep around multiple open connections and assign them per request. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational science. Most reasoning about it is at best rationalization of gut feelings, and at worst plain wrong." --GvR, python-ideas, 2009-03-01 From gleam.uahmed at gmail.com Sun Feb 6 12:33:34 2011 From: gleam.uahmed at gmail.com (uahmed) Date: Sun, 6 Feb 2011 22:33:34 +0500 Subject: Placing Transparent image over image Message-ID: Hi , I have 2 images and one on button and another one as a label i want that when label image comes on button so it show the transparent part of image , i have made this code but in this the transparent part is hide . Here is my code import fcntl, sys import sys import Skype4Py import functools import os import time from Tkinter import * import Image import ImageTk root = Tk() pic2a_dest = "pic2a.png" pic2a_open =Image.open(pic2a_dest) pic2a_handle = ImageTk.PhotoImage(pic2a_open) button1 = Button (root , image = pic2a_handle) button1.place(x=20,y=20) pic1a_dest = "pic1a.png" pic1a_open =Image.open(pic1a_dest) pic1a_handle = ImageTk.PhotoImage(pic1a_open) label1 = Label (root , image = pic1a_handle) label1.place(x=40,y=20) root.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pic1a.png Type: image/png Size: 7168 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pic2a.png Type: image/png Size: 9568 bytes Desc: not available URL: From calderone.jeanpaul at gmail.com Sun Feb 6 13:01:17 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Sun, 6 Feb 2011 10:01:17 -0800 (PST) Subject: sending through non-default gateway References: Message-ID: On Feb 6, 1:10?am, Nikola Skoric wrote: > Dana Sat, 5 Feb 2011 14:13:11 -0800, > Dan Stromberg kaze: > > > IIRC, this is an instance of what's called "source routing", and was > > largely shut off after network admins realized it was a security > > issue. > > > Of course, if you have root/administrator permission, you could > > probably do it. ?But if you have that, you could probably just fix the > > routing table. > > Yeah, I don't have admin priviledges, it's my office computer which is > supposed to be cut of the Internet. > > I did a bit of reading on source routing and I'd like to try it. Just > for fun, in case our router accepts such packets. So, is there a way > to do it in python? You don't need real source routing (and real source routed packets will probably be dropped by the first router that sees them). You just need to make a different decision at the first hop. You can do this with the SO_BINDTODEVICE option on a raw socket. But this probably also requires administrative privileges. Jean-Paul From grahn+nntp at snipabacken.se Sun Feb 6 13:41:37 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 6 Feb 2011 18:41:37 GMT Subject: Fully functioning email client in Python References: <7d75973e-8061-4da2-b265-3c18f19b8040@u3g2000vbe.googlegroups.com> Message-ID: On Sun, 2011-02-06, iaoua iaoua wrote: ... > In a nutshell my problem is this. I have > developed an intelligent conversational agent which dialogues with a > user to find out what they are really searching for. The domain is > open and helps the user find which businesses/websites offer the > services or products the user is looking for according to needs > elicited from the user during the dialogue. I have small but growing > base of experimental users who want to access the agent via email (the > agent can be quite slow at times due to the complexity of the system) > so that they can ask questions and forget about them until an answer > comes to their inbox. OK, so the "agent" becomes a server with a mail interface. > And so I need to extend my agent so that it can > receive and send emails and extract the relevant text answers to > questions from the user. This requires full threading capabilities and > automatic text extraction of only the new and relevant material (minus > signatures of course). > > Now, I'm not completely lazy and so I have already done a little > homework. I've been reading O'Reilly's Programming Python and > Foundations of Python Network Programming which have both been very > helpful in ascertaining that Python is a strong candidate solution. > Both books talk about the email (for message and header construction > and parsing) sendmail (for sending mail via SMTP) and poplib (for > receiving mail with POP3) libraries. ... > What I really need is a ready made fully functional Python client that > already has it that offers me a simple interface to extract text from > received messages along with a message id that I can use to associate > the response to a question with and allows me to send out new > questions or answers along with a message id I can use to track future > responses with. I need something that already has the whole shebang. > Can support POP3, IMAP, SSL authentication, message threading etc. > > Can anyone point to something that will save me the effort of building > this thing from scratch and first principles? Thanks in advance for > any useful suggestions. I imagine your only worry is the server side. What are your requirements on the system it's running on? If it's on Unix you don't need to do any network programming at all, and can forget about IMAP, POP3, SSL and SMTP. Using procmail you can arrange to start a program of your choice each time a mail arrives (and that program would put the message on your agent's work queue). To send mail, you feed the text and the recipient address into /usr/lib/sendmail. If you build the interface on POP3 and SMTP, you have to bypass the system's builtin mail capabilities. If on the other hand it's on Windows, there's certainly some very different scheme you have to follow (or bypass). /Jorgen -- // Jorgen Grahn O o . From itearn24 at gmail.com Sun Feb 6 14:43:12 2011 From: itearn24 at gmail.com (sahadat shamim) Date: Sun, 6 Feb 2011 11:43:12 -0800 (PST) Subject: Are Small Dogs Good with Kids? Message-ID: <2fa07209-a3bb-43fc-a4ec-c53cceda5a9b@y35g2000prc.googlegroups.com> Are little canines nice with children? Most people can't seem to come to a consensus about this query. individuals who regularly place rescue canines with adoptive more http://animals-world24.blogspot.com/2011/02/are-small-dogs-good-with-kids.html From steve+comp.lang.python at pearwood.info Sun Feb 6 16:58:19 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Feb 2011 21:58:19 GMT Subject: Fully functioning email client in Python References: <7d75973e-8061-4da2-b265-3c18f19b8040@u3g2000vbe.googlegroups.com> Message-ID: <4d4f197b$0$29972$c3e8da3$5496439d@news.astraweb.com> On Sat, 05 Feb 2011 17:34:41 -0800, iaoua iaoua wrote: > What I really need is a ready made fully functional Python client [...] > Can anyone point to something that will save me the effort of building > this thing from scratch and first principles? Thanks in advance for any > useful suggestions. Have you searched PyPI for something suitable? http://pypi.python.org/ -- Steven From spam at uce.gov Sun Feb 6 20:23:53 2011 From: spam at uce.gov (spam at uce.gov) Date: Sun, 06 Feb 2011 18:23:53 -0700 Subject: email.encoders.encode_base64 creates one line only Message-ID: This is with python 3.1.2 (r312:79147). I have not tried with 2.7. When I create an attachment with email.mime.image.MIMEImage, by default it uses email.encoders.encode_base64 for the encoder, but that results in a single line base64 string, instead of the recommended multiple 76-chars lines. This works with most MTA and MUA, but some of them choke on it. Is this a bug, or do I need to write my own _encoder? -- Yves. http://www.SollerS.ca/ http://blog.zioup.org/ From bob.martin at excite.com Mon Feb 7 02:19:34 2011 From: bob.martin at excite.com (Bob Martin) Date: Mon, 07 Feb 2011 07:19:34 GMT Subject: Are Small Dogs Good with Kids? References: <2fa07209-a3bb-43fc-a4ec-c53cceda5a9b@y35g2000prc.googlegroups.com> Message-ID: <8r9ko6Fpr9U1@mid.individual.net> in 651499 20110206 194312 sahadat shamim wrote: >Are little canines nice with children? Most people can't seem to come >to a consensus about this query. individuals who regularly place >rescue canines with adoptive >more >http://animals-world24.blogspot.com/2011/02/are-small-dogs-good-with-kids.html You cannot generalise. It depends on how they are brought up. My two terriers absolutely love children. From ian.g.kelly at gmail.com Mon Feb 7 02:31:01 2011 From: ian.g.kelly at gmail.com (Ian) Date: Sun, 6 Feb 2011 23:31:01 -0800 (PST) Subject: Are Small Dogs Good with Kids? References: <2fa07209-a3bb-43fc-a4ec-c53cceda5a9b@y35g2000prc.googlegroups.com> <8r9ko6Fpr9U1@mid.individual.net> Message-ID: <513ad5e7-db20-40e9-8b96-649c5e8211fd@l18g2000yqm.googlegroups.com> On Feb 7, 12:19?am, Bob Martin wrote: > You cannot generalise. ?It depends on how they are brought up. > My two terriers absolutely love children. Please don't reply to spam. From stefan_ml at behnel.de Mon Feb 7 04:20:50 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 07 Feb 2011 10:20:50 +0100 Subject: Are Small Dogs Good with Kids? In-Reply-To: <8r9ko6Fpr9U1@mid.individual.net> References: <2fa07209-a3bb-43fc-a4ec-c53cceda5a9b@y35g2000prc.googlegroups.com> <8r9ko6Fpr9U1@mid.individual.net> Message-ID: Bob Martin, 07.02.2011 08:19: > My two terriers absolutely love children. Hmmmm, tasty ... Stefan From tyler at tysdomain.com Mon Feb 7 09:51:44 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Mon, 07 Feb 2011 07:51:44 -0700 Subject: Are Small Dogs Good with Kids? In-Reply-To: <8r9ko6Fpr9U1@mid.individual.net> References: <2fa07209-a3bb-43fc-a4ec-c53cceda5a9b@y35g2000prc.googlegroups.com> <8r9ko6Fpr9U1@mid.individual.net> Message-ID: <4D500700.1000007@tysdomain.com> Not only does this have -nothing- to do with python, but you reproduced the spam yet again by quoting it... seriously? From d_vineet at yahoo.com Mon Feb 7 10:13:43 2011 From: d_vineet at yahoo.com (Vineet Deodhar) Date: Mon, 7 Feb 2011 07:13:43 -0800 (PST) Subject: Turbogears 2.1 with mako tmplates Message-ID: <896266.96416.qm@web32004.mail.mud.yahoo.com> Hi!, I am a python programmer. For web-based solutions, I have started learning TG 2.1 By and large, the documentation on TG 2.1 official site is a work-in-process. As regards to the templates, it tells how to go about Genshi. I wish to go with mako. Gone through the docs of mako (they are good). But still, it would be better if I can get a tutorial explaining using TG 2.1 with mako. (It will save me from re-inventing the wheel, if somebody has written docs on these lines). Can anybody point to any such tutorial? (I googled, but couldn't locate any convincing result). Thanks, Vineet -------------- next part -------------- An HTML attachment was scrubbed... URL: From ckkart at hoc.net Mon Feb 7 10:34:41 2011 From: ckkart at hoc.net (Christian K.) Date: Mon, 07 Feb 2011 16:34:41 +0100 Subject: re.Scanner - match python dot notation Message-ID: Hi, I am trying to find a regexp to be used with re.Scanner that matches the 'package.module.member' syntax. More specifically I want to parse function strings like numpy.sin(x*a+w) and sort out variables/constants. This one here works using re.match but fails when used with Scanner (due to the grouping () I guess). r'((?=.*[a-zA-Z])(?=.+[\.]).+)[\(\+\-]+' I highly appreciate your comments. Regards, christian From mauro.caceres at gmail.com Mon Feb 7 11:26:33 2011 From: mauro.caceres at gmail.com (Mauro Caceres) Date: Mon, 7 Feb 2011 13:26:33 -0300 Subject: returning all matching groups with re.search() In-Reply-To: References: Message-ID: >>> import re >>> help(re.findall) Help on function findall in module re: findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result. >>> re.findall('e','fredbarneybettywilma') ['e', 'e', 'e'] -- Mauro C?ceres -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Feb 7 11:47:11 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 07 Feb 2011 16:47:11 +0000 Subject: re.Scanner - match python dot notation In-Reply-To: References: Message-ID: <4D50220F.7070205@mrabarnett.plus.com> On 07/02/2011 15:34, Christian K. wrote: > Hi, > > I am trying to find a regexp to be used with re.Scanner that matches the > 'package.module.member' syntax. More specifically I want to parse > function strings like > > numpy.sin(x*a+w) > > and sort out variables/constants. > > This one here works using re.match but fails when used with Scanner (due > to the grouping () I guess). > > r'((?=.*[a-zA-Z])(?=.+[\.]).+)[\(\+\-]+' > > I highly appreciate your comments. > > Regards, christian > I'm not sure about your regex, but I'd probably use this: r'[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*' From pruebauno at latinmail.com Mon Feb 7 11:52:44 2011 From: pruebauno at latinmail.com (nn) Date: Mon, 7 Feb 2011 08:52:44 -0800 (PST) Subject: itertools.groupby usage to get structured data References: <7c46612d-d435-4e4f-bfa0-e7dd5918f66c@24g2000yqa.googlegroups.com> Message-ID: On Feb 5, 7:12?am, Peter Otten <__pete... at web.de> wrote: > Slafs wrote: > > Hi there! > > > I'm having trouble to wrap my brain around this kind of problem: > > > What I have : > > ? 1) list of dicts > > ? 2) list of keys that i would like to be my grouping arguments of > > elements from 1) > > ? 3) list of keys that i would like do "aggregation" on the elements > > of 1) with some function e.g. sum > > > For instance i got: > > 1) [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 }, > > ? ? ? { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 }, > > ? ? ? {'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0}, ... ] > > 2) ['g1', 'g2'] > > 3) ['s_v1', 's_v2'] > > > To be precise 1) is a result of a values_list method from a QuerySet > > in Django; 2) is the arguments for that method; 3) those are the > > annotation keys. so 1) is a result of: > > ? ?qs.values_list('g1', 'g2').annotate(s_v1=Sum('v1'), s_v2=Sum('v2')) > > > What i want to have is: > > a "big" nested dictionary with 'g1' values as 1st level keys and a > > dictionary of aggregates and "subgroups" in it. > > > In my example it would be something like this: > > { > > ? 1 : { > > ? ? ? ? ? 's_v1' : 7.0, > > ? ? ? ? ? 's_v2' : 6.5, > > ? ? ? ? ? 'g2' :{ > > ? ? ? ? ? ? ? ? ? ?8 : { > > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v1' : 5.0, > > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v2' : 3.5 }, > > ? ? ? ? ? ? ? ? ? ?9 : ?{ > > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v1' : 2.0, > > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v2' : 3.0 } > > ? ? ? ? ? ? ? ? } > > ? ? ? ?}, > > ? 2 : { > > ? ? ? ? ? ?'s_v1' : 6.0, > > ? ? ? ? ? ?'s_v2' : 8.0, > > ? ? ? ? ? ?'g2' : { > > ? ? ? ? ? ? ? ? ? ? 8 : { > > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v1' : 6.0, > > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v2' : 8.0} > > ? ? ? ? ? ?} > > ? ? ? ?}, > > ... > > } > > > # notice the summed values of s_v1 and s_v2 when g1 == 1 > > > I was looking for a solution that would let me do that kind of > > grouping with variable lists of 2) and 3) i.e. having also 'g3' as > > grouping element so the 'g2' dicts could also have their own > > "subgroup" and be even more nested then. > > I was trying something with itertools.groupby and updating nested > > dicts, but as i was writing the code it started to feel too verbose to > > me :/ > > > Do You have any hints maybe? because i'm kind of stucked :/ > > > Regards > > > S?awek > > Not super-efficient, but simple: > > $ cat python sumover.py > cat: python: No such file or directory > data = [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 }, > ? ? ? ? ?{ 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 }, > ? ? ? ? ?{'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0}] > sum_over = ["s_v1", "s_v2"] > group_by = ["g1", "g2"] > > wanted = { > ? 1 : { > ? ? ? ? ? 's_v1' : 7.0, > ? ? ? ? ? 's_v2' : 6.5, > ? ? ? ? ? 'g2' :{ > ? ? ? ? ? ? ? ? ? ?8 : { > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v1' : 5.0, > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v2' : 3.5 }, > ? ? ? ? ? ? ? ? ? ?9 : ?{ > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v1' : 2.0, > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v2' : 3.0 } > ? ? ? ? ? ? ? ? } > ? ? ? ?}, > ? 2 : { > ? ? ? ? ? ?'s_v1' : 6.0, > ? ? ? ? ? ?'s_v2' : 8.0, > ? ? ? ? ? ?'g2' : { > ? ? ? ? ? ? ? ? ? ? 8 : { > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v1' : 6.0, > ? ? ? ? ? ? ? ? ? ? ? ? ? 's_v2' : 8.0} > ? ? ? ? ? ?} > ? ? ? ?}, > > } > > def calc(data, group_by, sum_over): > ? ? tree = {} > ? ? group_by = group_by + [None] > ? ? for item in data: > ? ? ? ? d = tree > ? ? ? ? for g in group_by: > ? ? ? ? ? ? for so in sum_over: > ? ? ? ? ? ? ? ? d[so] = d.get(so, 0.0) + item[so] > ? ? ? ? ? ? if g: > ? ? ? ? ? ? ? ? d = d.setdefault(g, {}).setdefault(item[g], {}) > ? ? return tree > > got = calc(data, group_by, sum_over)[group_by[0]] > assert got == wanted > $ python sumover.py > $ > > Untested. Very clever. I didn't understand how it worked until I rewrote it like this: def calc(data, group_by, sum_over): tree = {} group_by = [None] + group_by for item in data: d = tree for g in group_by: if g: d = d.setdefault(g, {}).setdefault(item[g], {}) for so in sum_over: d[so] = d.get(so, 0.0) + item[so] return tree Processing "None" in the last round of the loop was throwing me off. From __peter__ at web.de Mon Feb 7 12:28:57 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 07 Feb 2011 18:28:57 +0100 Subject: re.Scanner - match python dot notation References: Message-ID: Christian K. wrote: > I am trying to find a regexp to be used with re.Scanner that matches the > 'package.module.member' syntax. More specifically I want to parse > function strings like > > numpy.sin(x*a+w) > > and sort out variables/constants. No direct answer, but regarding your ultimate goal the ast module might be a better starting point. From nick at fly.srk.fer.hr Mon Feb 7 12:43:56 2011 From: nick at fly.srk.fer.hr (Nikola Skoric) Date: Mon, 7 Feb 2011 17:43:56 +0000 (UTC) Subject: splitting by double newline Message-ID: Hello everybody, I'd like to split a file by double newlines, but portably. Now, splitting by one or more newlines is relatively easy: self.tables = re.split("[\r\n]+", bulk) But, how can I split on double newlines? I tried several approaches, but none worked... -- "Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams" From dvicente at full-on-net.com Mon Feb 7 12:45:31 2011 From: dvicente at full-on-net.com (David Vicente) Date: Mon, 7 Feb 2011 18:45:31 +0100 Subject: Remove whitespaces and line breaks in a XML file Message-ID: <002701cbc6ee$df359d20$9da0d760$@com> Hi, I?m parsing an xml file with xml.etree. It works correctly, but I have a problem with the text attribute of the elements which should be empty. For example, in this case: Ken The text element of ?book? should be empty, but it returns me some whitespaces and break lines. I can?t get remove these whitespaces without remove information. Some idea? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Feb 7 13:02:05 2011 From: ian.g.kelly at gmail.com (Ian) Date: Mon, 7 Feb 2011 10:02:05 -0800 (PST) Subject: splitting by double newline References: Message-ID: <85980d81-1c01-4f71-a9da-77fb906c5358@s11g2000yqh.googlegroups.com> On Feb 7, 10:43?am, Nikola Skoric wrote: > Hello everybody, > > I'd like to split a file by double newlines, but portably. Now, > splitting by one or more newlines is relatively easy: > > self.tables = re.split("[\r\n]+", bulk) > > But, how can I split on double newlines? I tried several approaches, > but none worked... self.tables = re.split(r'(?:\r\n){2,}|\r{2,}|\n{2,}', bulk) From __peter__ at web.de Mon Feb 7 13:20:38 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 07 Feb 2011 19:20:38 +0100 Subject: splitting by double newline References: Message-ID: Nikola Skoric wrote: > Hello everybody, > > I'd like to split a file by double newlines, but portably. Now, > splitting by one or more newlines is relatively easy: > > self.tables = re.split("[\r\n]+", bulk) > > But, how can I split on double newlines? I tried several approaches, > but none worked... If you open the file in universal newline mode with with open(filename, "U") as f: bulk = f.read() your data will only contain "\n". You can then split with blocks = bulk.split("\n\n") # exactly one empty line or blocks = re.compile(r"\n{2,}").split(bulk) # one or more empty lines One last variant that doesn't read in the whole file and accepts lines with only whitespace as empty: with open(filename, "U") as f: blocks = ("".join(group) for empty, group in itertools.groupby(f, key=str.isspace) if not empty) From vs at it.uu.se Mon Feb 7 13:47:55 2011 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 07 Feb 2011 19:47:55 +0100 Subject: Universal Feed Browser problem in feedparser.py Message-ID: <4D503E5B.2080006@it.uu.se> I am running Python 2.6 on a Windows Vista (32-bit) platform. I recently installed the Universal Feed Parser package (feedparser-5-0). When I try to execute the following commands: >>> import feedparser >>> d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml") which is given at http://www.feedparser.org/ I get an Assertion error in the following function in feedparser.py def __getattr__(self, key): try: return self.__dict__[key] except KeyError: pass try: assert not key.startswith('_') <------- Error occurs when this statement is executed. return self.__getitem__(key) except: raise AttributeError, "object has no attribute '%s'" % key Why does the error occur and how should he be corrected? From ckkart at hoc.net Mon Feb 7 13:53:04 2011 From: ckkart at hoc.net (Christian K.) Date: Mon, 07 Feb 2011 19:53:04 +0100 Subject: re.Scanner - match python dot notation In-Reply-To: <4D50220F.7070205@mrabarnett.plus.com> References: <4D50220F.7070205@mrabarnett.plus.com> Message-ID: Am 07.02.11 17:47, schrieb MRAB: > On 07/02/2011 15:34, Christian K. wrote: >> Hi, >> >> I am trying to find a regexp to be used with re.Scanner that matches the >> 'package.module.member' syntax. More specifically I want to parse >> function strings like >> >> numpy.sin(x*a+w) >> >> and sort out variables/constants. >> >> This one here works using re.match but fails when used with Scanner (due >> to the grouping () I guess). >> >> r'((?=.*[a-zA-Z])(?=.+[\.]).+)[\(\+\-]+' >> >> I highly appreciate your comments. >> >> Regards, christian >> > I'm not sure about your regex, but I'd probably use this: > > r'[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*' Perfect, thanks. I changed the last * to a + so that the string must contain a '.' to match. Christian From alice at gothcandy.com Mon Feb 7 13:57:21 2011 From: alice at gothcandy.com (=?utf-8?Q?Alice_Bevan=E2=80=93McGregor?=) Date: Mon, 7 Feb 2011 10:57:21 -0800 Subject: Turbogears 2.1 with mako tmplates References: <896266.96416.qm@web32004.mail.mud.yahoo.com> Message-ID: On 2011-02-07 07:13:43 -0800, Vineet Deodhar said: > For web-based solutions, I have started learning TG 2.1 > By and large, the documentation on TG 2.1 official site is a work-in-process. > As regards to the templates, it tells how to go about Genshi. > I wish to go with mako. > Gone through the docs of mako (they are good). > But still, it would be better if I can get a tutorial explaining using > TG 2.1 with mako. > (It will save me from re-inventing the wheel, if somebody has written > docs on these lines). > Can anybody point to any such tutorial? > (I googled, but couldn't locate any convincing result). I believe you will have signifigantly greater success having TurboGears questions answered when asked on the appropriate forum: http://groups.google.com/group/turbogears ? Alice. From nagle at animats.com Mon Feb 7 15:32:24 2011 From: nagle at animats.com (John Nagle) Date: Mon, 07 Feb 2011 12:32:24 -0800 Subject: Fully functioning email client in Python In-Reply-To: <7d75973e-8061-4da2-b265-3c18f19b8040@u3g2000vbe.googlegroups.com> References: <7d75973e-8061-4da2-b265-3c18f19b8040@u3g2000vbe.googlegroups.com> Message-ID: <4d5056d7$0$10549$742ec2ed@news.sonic.net> On 2/5/2011 5:34 PM, iaoua iaoua wrote: > What I really need is a ready made fully functional Python client that > already has it that offers me a simple interface to extract text from > received messages along with a message id that I can use to associate > the response to a question with and allows me to send out new > questions or answers along with a message id I can use to track future > responses with. I need something that already has the whole shebang. > Can support POP3, IMAP, SSL authentication, message threading etc. It sounds like you need an SMTP receiving server and an SMTP sender, not a user-type client. See http://docs.python.org/library/smtpd.html for a simple server that will handle incoming messages, and http://docs.python.org/library/smtplib.html for an SMTP sender that can reply to them. Those are standard Python functions. You can run this on most server-type machines. It's best if you have an upstream server configured to do spam filtering and forwarding to your server, or you'll get vast amounts of junk coming into your system. Have the upstream machine forward to a nonstandard mail port (like "example.com:2525") if the server machine already has a mail server. This will allow the existing mail server to run. John Nagle From stefan_ml at behnel.de Mon Feb 7 15:54:30 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 07 Feb 2011 21:54:30 +0100 Subject: Remove whitespaces and line breaks in a XML file In-Reply-To: <002701cbc6ee$df359d20$9da0d760$@com> References: <002701cbc6ee$df359d20$9da0d760$@com> Message-ID: David Vicente, 07.02.2011 18:45: > I?m parsing an xml file with xml.etree. It works correctly, but I have a > problem with the text attribute of the elements which should be empty. For > example, in this case: > > > > Ken > > > > > > The text element of ?book? should be empty, but it returns me some > whitespaces and break lines. I can?t get remove these whitespaces without > remove information. Only a DTD (or schema) can provide the information which whitespace in an XML document is meaningful and which isn't, so there is no generic way to "do it right", especially not for something as generic as an XML parser. What may work for you is to check if an Element has children and only whitespace as text ("not el.text or not el.text.strip()"), and only then replace it by None. Stefan From nick at fly.srk.fer.hr Mon Feb 7 16:10:55 2011 From: nick at fly.srk.fer.hr (Nikola Skoric) Date: Mon, 7 Feb 2011 21:10:55 +0000 (UTC) Subject: splitting by double newline References: Message-ID: Dana Mon, 07 Feb 2011 19:20:38 +0100, Peter Otten <__peter__ at web.de> kaze: > with open(filename, "U") as f: Oh, fabulous. Thanks! -- "Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams" From nick at fly.srk.fer.hr Mon Feb 7 16:15:54 2011 From: nick at fly.srk.fer.hr (Nikola Skoric) Date: Mon, 7 Feb 2011 21:15:54 +0000 (UTC) Subject: splitting by double newline References: <85980d81-1c01-4f71-a9da-77fb906c5358@s11g2000yqh.googlegroups.com> Message-ID: Dana Mon, 7 Feb 2011 10:02:05 -0800 (PST), Ian kaze: > self.tables = re.split(r'(?:\r\n){2,}|\r{2,}|\n{2,}', bulk) Thanks! I tried without "?:", but it didn't work. Can you tell me why is it important that group is noncapturing? -- "Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams" From miki.tebeka at gmail.com Mon Feb 7 16:16:11 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 7 Feb 2011 13:16:11 -0800 (PST) Subject: Universal Feed Browser problem in feedparser.py In-Reply-To: Message-ID: > >>> import feedparser > >>> d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml") This works for me, are you sure it's not a network problem in your side? (what happens if you try to open this link in a browser?) From miki.tebeka at gmail.com Mon Feb 7 16:16:11 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 7 Feb 2011 13:16:11 -0800 (PST) Subject: Universal Feed Browser problem in feedparser.py In-Reply-To: Message-ID: > >>> import feedparser > >>> d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml") This works for me, are you sure it's not a network problem in your side? (what happens if you try to open this link in a browser?) From trylks at gmail.com Mon Feb 7 17:26:07 2011 From: trylks at gmail.com (trylks) Date: Mon, 7 Feb 2011 23:26:07 +0100 Subject: Why not "list = ftplib.FTP.dir()" ? Message-ID: I don't know if it is ftplib or just me, but something feels terribly wrong in this: from ftplib import FTP > from functools import partial > > class MyFTP(FTP): > def dir(self): > l = [] > super(MyFTP, self).dir(partial(lambda l, e: l.append(e.split()), l)) > return l > Unfortunately 'MLSD' is not available in the server I have to use. (I need to get the list of folders and files modified since last access, hence split). Cheers. -------------- next part -------------- An HTML attachment was scrubbed... URL: From richardh at dslextreme.com Mon Feb 7 17:27:06 2011 From: richardh at dslextreme.com (Richard Holmes) Date: Mon, 07 Feb 2011 14:27:06 -0800 Subject: PIL Open Problem Message-ID: I'm trying to create an image for use in Tkinter. If I understand the PIL documentation correctly, I first need to import Image, then create an instance of the Image class and call 'open' (this according to the documentation). When I try to do this using the model in the documentation, I get: Traceback (most recent call last): File "todo.py", line 202, in im = Image.open(cwd + r'\delete.GIF', 'r') AttributeError: class Image has no attribute 'open' where 'cwd' is the current working directory obtained using the os module. When I import Image into IDLE and enter help(Image.open), IDLE is quite happy to give me the info about the function. Can someone point out to me the folly of my ways? TIA! Dick Holmes From kb1pkl at aim.com Mon Feb 7 17:28:45 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Mon, 07 Feb 2011 17:28:45 -0500 Subject: PIL Open Problem In-Reply-To: References: Message-ID: <4D50721D.2090602@aim.com> On 02/07/2011 05:27 PM, Richard Holmes wrote: > I'm trying to create an image for use in Tkinter. If I understand the > PIL documentation correctly, I first need to import Image, then > create an instance of the Image class and call 'open' Don't do that. This is wrong: import Image im = Image.Image() im = im.open(foo) This is good: import Image im = Image.open(foo) From ben+python at benfinney.id.au Mon Feb 7 17:47:32 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 08 Feb 2011 09:47:32 +1100 Subject: PIL Open Problem References: Message-ID: <87tygfqx6j.fsf@benfinney.id.au> Richard Holmes writes: > I'm trying to create an image for use in Tkinter. If I understand the > PIL documentation correctly, I first need to import Image, then > create an instance of the Image class and call 'open' (this according > to the documentation). When I try to do this using the model in the > documentation, I get: Please show the code you used that generated this traceback. > Traceback (most recent call last): > File "todo.py", line 202, in > im = Image.open(cwd + r'\delete.GIF', 'r') > AttributeError: class Image has no attribute 'open' The line of code shown in the traceback is calling the ?open? method on the ?Image? class ? which has no such method, as the error tells you. > Can someone point out to me the folly of my ways? It will be much easier when we see some code. Post a minimal, working example that still shows the behaviour you want explained. -- \ ?If you make people think they're thinking, they'll love you; | `\ but if you really make them think, they'll hate you.? ?Donald | _o__) Robert Perry Marquis | Ben Finney From ian.g.kelly at gmail.com Mon Feb 7 17:48:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 7 Feb 2011 15:48:51 -0700 Subject: Why not "list = ftplib.FTP.dir()" ? In-Reply-To: References: Message-ID: On Mon, Feb 7, 2011 at 3:26 PM, trylks wrote: > I don't know if it is ftplib or just me, but something feels terribly wrong > in this: > >> from ftplib import FTP >> from functools import partial >> >> class MyFTP(FTP): >> ? def dir(self): >> ??? l = [] >> ??? super(MyFTP, self).dir(partial(lambda l, e: l.append(e.split()), l)) >> ??? return l No need to use partial here. You can simplify that to: super(MyFTP, self).dir(lambda e: l.append(e.split())) From python at mrabarnett.plus.com Mon Feb 7 18:02:28 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 07 Feb 2011 23:02:28 +0000 Subject: splitting by double newline In-Reply-To: References: <85980d81-1c01-4f71-a9da-77fb906c5358@s11g2000yqh.googlegroups.com> Message-ID: <4D507A04.40400@mrabarnett.plus.com> On 07/02/2011 21:15, Nikola Skoric wrote: > Dana Mon, 7 Feb 2011 10:02:05 -0800 (PST), > Ian kaze: >> self.tables = re.split(r'(?:\r\n){2,}|\r{2,}|\n{2,}', bulk) > > Thanks! > > I tried without "?:", but it didn't work. Can you tell me why is it > important that group is noncapturing? > The scanner uses capture groups to identify which part matched. If you provide additional capture groups it has problems... From richardh at dslextreme.com Mon Feb 7 18:09:24 2011 From: richardh at dslextreme.com (Richard Holmes) Date: Mon, 07 Feb 2011 15:09:24 -0800 Subject: PIL Open Problem References: Message-ID: On Mon, 07 Feb 2011 17:28:45 -0500, Corey Richardson wrote: >On 02/07/2011 05:27 PM, Richard Holmes wrote: >> I'm trying to create an image for use in Tkinter. If I understand the >> PIL documentation correctly, I first need to import Image, then >> create an instance of the Image class and call 'open' > >Don't do that. This is wrong: > >import Image >im = Image.Image() >im = im.open(foo) > >This is good: > >import Image >im = Image.open(foo) Uh, thanks, Corey, but that's what I'm doing. See Traceback: Traceback (most recent call last): File "todo.py", line 202, in im = Image.open(cwd + r'\delete.GIF', 'r') AttributeError: class Image has no attribute 'open' From ben+python at benfinney.id.au Mon Feb 7 18:31:14 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 08 Feb 2011 10:31:14 +1100 Subject: PIL Open Problem References: Message-ID: <87k4hbqv5p.fsf@benfinney.id.au> Richard Holmes writes: > On Mon, 07 Feb 2011 17:28:45 -0500, Corey Richardson > wrote: > >This is good: > > > >import Image > >im = Image.open(foo) > Uh, thanks, Corey, but that's what I'm doing. See Traceback: Without code, we can't see what you're doing. Please post a minimal working example that demonstrates the behaviour you want explained. -- \ ?Always do right. This will gratify some people, and astonish | `\ the rest.? ?Mark Twain | _o__) | Ben Finney From richardh at dslextreme.com Mon Feb 7 18:35:44 2011 From: richardh at dslextreme.com (Richard Holmes) Date: Mon, 07 Feb 2011 15:35:44 -0800 Subject: PIL Open Problem References: <87tygfqx6j.fsf@benfinney.id.au> Message-ID: <4c01l6hdnmd70mfb5o7nhp3vrehejr4cif@4ax.com> On Tue, 08 Feb 2011 09:47:32 +1100, Ben Finney wrote: >Richard Holmes writes: > >> I'm trying to create an image for use in Tkinter. If I understand the >> PIL documentation correctly, I first need to import Image, then >> create an instance of the Image class and call 'open' (this according >> to the documentation). When I try to do this using the model in the >> documentation, I get: > >Please show the code you used that generated this traceback. > >> Traceback (most recent call last): >> File "todo.py", line 202, in >> im = Image.open(cwd + r'\delete.GIF', 'r') >> AttributeError: class Image has no attribute 'open' > >The line of code shown in the traceback is calling the ?open? method on >the ?Image? class ? which has no such method, as the error tells you. > >> Can someone point out to me the folly of my ways? > >It will be much easier when we see some code. Post a minimal, working >example that still shows the behaviour you want explained. Thanks, Ben. It turns out that I imported both Image and Tkinter and Tkinter has an Image class that masked the Image class in the Image module. I solved the problem by moving the Image code to a separate module From dwayneblind at gmail.com Mon Feb 7 18:37:09 2011 From: dwayneblind at gmail.com (Dwayne Blind) Date: Tue, 8 Feb 2011 00:37:09 +0100 Subject: socket.rcv timeout while-loop In-Reply-To: <4D4C37A9.5060601@ixokai.io> References: <4D4AEE18.5050301@ixokai.io> <4D4BDA56.3040502@sequans.com> <4D4C2FB4.2070503@ixokai.io> <4D4C37A9.5060601@ixokai.io> Message-ID: Dear Stephen, Thanks for telling me this all looked very peculiar. As you said, it did not really need solving. Cheers, Dwayne 2011/2/4 Stephen Hansen > On 2/4/11 9:16 AM, Dwayne Blind wrote: > > @ Stephen Hansen > > Now I am pretty much worried. :'( > > Why? This is all sounding like a problem that isn't actually a problem. > > I think you may have over-analyzed yourself into a corner and think you > have something to solve which doesn't really need solving. :) > > -- > > Stephen Hansen > ... Also: Ixokai > ... Mail: me+list/python (AT) ixokai (DOT) io > ... Blog: http://meh.ixokai.io/ > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Joshua.R.English at gmail.com Mon Feb 7 18:46:17 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 7 Feb 2011 15:46:17 -0800 (PST) Subject: Remove whitespaces and line breaks in a XML file In-Reply-To: Message-ID: <9de1ca25-550d-4591-8255-c07d3e5e7b15@glegroupsg2000goo.googlegroups.com> I found the code posted at http://infix.se/2007/02/06/gentlemen-indent-your-xml quite helpful in turning my xml into human-readable structures. It works best for XML-Data. Josh From Joshua.R.English at gmail.com Mon Feb 7 18:46:17 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 7 Feb 2011 15:46:17 -0800 (PST) Subject: Remove whitespaces and line breaks in a XML file In-Reply-To: Message-ID: <9de1ca25-550d-4591-8255-c07d3e5e7b15@glegroupsg2000goo.googlegroups.com> I found the code posted at http://infix.se/2007/02/06/gentlemen-indent-your-xml quite helpful in turning my xml into human-readable structures. It works best for XML-Data. Josh From rantingrick at gmail.com Mon Feb 7 18:54:15 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 7 Feb 2011 15:54:15 -0800 (PST) Subject: PIL Open Problem References: <87tygfqx6j.fsf@benfinney.id.au> <4c01l6hdnmd70mfb5o7nhp3vrehejr4cif@4ax.com> Message-ID: On Feb 7, 5:35?pm, Richard Holmes wrote: > Thanks, Ben. It turns out that I imported both Image and Tkinter and > Tkinter has an Image class that masked the Image class in the Image > module. I solved the problem by moving the Image code to a separate > module Yes an another great example of why "from Tkinter import *" is a very *very* bad idea. Use "import Tkinter as tk" to solve the dilemma. No need to export code to another module. Next time you have an object that should have an attribute but does not, print the repr() of the object to find out what you are working with before clawing your eyeballs out in frustration :). >>> from Tkinter import * >>> Image use the repr() function in a script ... print repr(Image) From ben+python at benfinney.id.au Mon Feb 7 18:56:52 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 08 Feb 2011 10:56:52 +1100 Subject: PIL Open Problem References: <87tygfqx6j.fsf@benfinney.id.au> <4c01l6hdnmd70mfb5o7nhp3vrehejr4cif@4ax.com> Message-ID: <87fwrzqtyz.fsf@benfinney.id.au> Richard Holmes writes: > Thanks, Ben. It turns out that I imported both Image and Tkinter and > Tkinter has an Image class that masked the Image class in the Image > module. I solved the problem by moving the Image code to a separate > module This is a classic problem known as ?namespace clobbering?. It is best to *avoid* the recommendations made in many libraries of ?from foo import *?, because that will clobber any names in your namespace that happen to match names in the ?foo? module. Rather, import Tkinter and PIL as distinct namespaces:: >>> import PIL.Image >>> import Tkinter as tk >>> tk.Image >>> PIL.Image >> '/usr/lib/python2.6/dist-packages/PIL/Image.pyc'> and then you know that none of the names from those modules will clobber existing ones. -- \ ?Those who write software only for pay should go hurt some | `\ other field.? ?Erik Naggum, in _gnu.misc.discuss_ | _o__) | Ben Finney From rantingrick at gmail.com Mon Feb 7 18:59:17 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 7 Feb 2011 15:59:17 -0800 (PST) Subject: Why not "list = ftplib.FTP.dir()" ? References: Message-ID: <7ee97b60-b996-4795-9cb6-a1aab3623cbf@24g2000yqa.googlegroups.com> On Feb 7, 4:48?pm, Ian Kelly wrote: > On Mon, Feb 7, 2011 at 3:26 PM, trylks wrote: > > I don't know if it is ftplib or just me, but something feels terribly wrong > > in this: > > >> from ftplib import FTP > >> from functools import partial > > >> class MyFTP(FTP): > >> ? def dir(self): > >> ??? l = [] > >> ??? super(MyFTP, self).dir(partial(lambda l, e: l.append(e.split()), l)) > >> ??? return l > > No need to use partial here. ?You can simplify that to: > > super(MyFTP, self).dir(lambda e: l.append(e.split())) Why not...? MyFTP.dir(self, lambda e: l.append(e.split())) ...super is not needed when you "know" the name of the object. And now (without super) you can "see" the path of self just as Guido intended! super can be super confusing to noobs. From anikom15 at gmail.com Mon Feb 7 19:10:31 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Mon, 07 Feb 2011 16:10:31 -0800 Subject: PIL Open Problem In-Reply-To: References: <87tygfqx6j.fsf@benfinney.id.au> <4c01l6hdnmd70mfb5o7nhp3vrehejr4cif@4ax.com> Message-ID: <1297123831.5134.2.camel@localhost.localdomain> On Mon, 2011-02-07 at 15:54 -0800, rantingrick wrote: > On Feb 7, 5:35 pm, Richard Holmes wrote: > > > Thanks, Ben. It turns out that I imported both Image and Tkinter and > > Tkinter has an Image class that masked the Image class in the Image > > module. I solved the problem by moving the Image code to a separate > > module > > Yes an another great example of why "from Tkinter import *" is a very > *very* bad idea. Use "import Tkinter as tk" to solve the dilemma. No > need to export code to another module. Next time you have an object > that should have an attribute but does not, print the repr() of the > object to find out what you are working with before clawing your > eyeballs out in frustration :). > > > >>> from Tkinter import * > >>> Image > > > > use the repr() function in a script ... print repr(Image) Or just print(Image). print() automatically calls str() on an object. -------------- next part -------------- An HTML attachment was scrubbed... URL: From richardh at dslextreme.com Mon Feb 7 19:43:50 2011 From: richardh at dslextreme.com (Richard Holmes) Date: Mon, 07 Feb 2011 16:43:50 -0800 Subject: PIL Open Problem References: <87tygfqx6j.fsf@benfinney.id.au> <4c01l6hdnmd70mfb5o7nhp3vrehejr4cif@4ax.com> <87fwrzqtyz.fsf@benfinney.id.au> Message-ID: <3d41l69mdv8ctva1piso0ibqvjlrnnnatr@4ax.com> On Tue, 08 Feb 2011 10:56:52 +1100, Ben Finney wrote: >Richard Holmes writes: > >> Thanks, Ben. It turns out that I imported both Image and Tkinter and >> Tkinter has an Image class that masked the Image class in the Image >> module. I solved the problem by moving the Image code to a separate >> module > >This is a classic problem known as ?namespace clobbering?. > >It is best to *avoid* the recommendations made in many libraries of >?from foo import *?, because that will clobber any names in your >namespace that happen to match names in the ?foo? module. > >Rather, import Tkinter and PIL as distinct namespaces:: > > >>> import PIL.Image > >>> import Tkinter as tk > >>> tk.Image > > >>> PIL.Image > >>> '/usr/lib/python2.6/dist-packages/PIL/Image.pyc'> > >and then you know that none of the names from those modules will clobber >existing ones. Thanks. Message understood. From r1chardj0n3s at gmail.com Mon Feb 7 22:38:54 2011 From: r1chardj0n3s at gmail.com (Richard Jones) Date: Tue, 8 Feb 2011 14:38:54 +1100 Subject: Python Game Programming Challenge 12 (April 2011) is coming! Message-ID: The 12th Python Game Programming Challenge (PyWeek) is coming. It'll run from the 3rd to the 10th of April. The PyWeek challenge: - Invites entrants to write a game in one week from scratch either as an individual or in a team, - Is intended to be challenging and fun, - Will hopefully increase the public body of game tools, code and expertise, - Will let a lot of people actually finish a game, and - May inspire new projects (with ready made teams!) Richard http://pyweek.org/12/ From wolfson at gmail.com Mon Feb 7 23:51:58 2011 From: wolfson at gmail.com (Ben) Date: Mon, 7 Feb 2011 20:51:58 -0800 (PST) Subject: smtpd bug? Message-ID: <01d37a76-df69-4289-bc4f-dc855fee9ce9@i39g2000prd.googlegroups.com> I've been using smtpd.py to implement a kind of cowboy SMTP server (only overriding process_message), and inevitably after a certain time the server stops accepting incoming connections: the socket on which it was formerly listening gets closed. I ran it using strace and discovered that it would get ENOTCONN on some just-accepted socket in a call to getpeername(), and then close the *listening* socket. This seems to be caused by the line channel = SMTPChannel(self, conn, addr) in smtpd.py and handle_error() in the definition of asyncore.dispatcher, which finishes by calling self.handle_close() [1]. The result of this is that when the call to getpeername() in the constructor for SMTPChannel raises ENOTCONN (or any other exception), it unwinds via asyncore.dispatcher.handle_read_event(), to asyncore.read(), where the SMTPServer instance gets its handle_error method called on it, eventually closing its listening socket. But the error was in the socket we just accepted---not the listening socket. [1] I'm actually using python2.4, since that's what's installed on the server; there, the handle_error() method simply finishes by calling self.close(). In fact, AFAICT, there's another problem in 3.1: neither asyncore.dispatcher nor smtpd.SMTPServer (nor any of its subclasses in smtpd.py) defines a method handle_close(); asyncore.dispatcher passes attribute lookups to its socket object via __getattr__, but sockets don't have a handle_close method either---so it seems as if, if handle_close() is ever called, it'll just generate a new error. From richard at python.org Tue Feb 8 03:32:47 2011 From: richard at python.org (Richard Jones) Date: Tue, 8 Feb 2011 19:32:47 +1100 Subject: PyCon Australia 2011: 20th & 21st August, Sydney Masonic Center Message-ID: The second PyCon Australia will be held in Sydney on the weekend of the 20th and 21st of August at the Sydney Masonic Center. The first PyCon Australia was held in June 2010 and attracted over 200 Python programming enthusiasts. The second event is expected to host over 250 attendees. The weekend will see dozens of presentations introducing; - Python programming and techniques, - web programming, - business applications, - game development, - education, science and mathematics, - social issues, - testing, databases, documentation and more! We are hoping to organise sprints on the days following the conference proper. International guests should note that Kiwi PyCon is to run on the following weekend, making it a great opportunity to attend a couple of awesome Down Under conferences and hopefully do some sprinting with the locals. Richard Jones http://pycon-au.org/ PyCon AU Committee From michele.petrazzo at REMOVE_me_unipex.it Tue Feb 8 03:57:35 2011 From: michele.petrazzo at REMOVE_me_unipex.it (Michele Petrazzo) Date: Tue, 08 Feb 2011 09:57:35 +0100 Subject: exec, import and isinstance Message-ID: <4d510586$2@news.x-privat.org> Hi all, I'm playing with python internals and I'm discovering a strange behavior of isinstance. Considering the following test case: test/bar.py test/b.py test/a/__init__.py test/a/foo.py -- __init__.py -> empty --- foo.py: class foo: pass c = foo --- b.py def ret(): d = {} #s = "import sys;sys.path.append('a');import foo" ## this cause the problem s = "import sys;from a import foo" exec s in d return d["foo"].c --- bar.py import a.foo import b c1 = a.foo.foo c2 = b.ret() print c1, c2 print isinstance(c2(), c1) --- Executing bar.py, I receive: a.foo.foo a.foo.foo True But, if I replace the indicated line, python doesn't recognize anymore the instance and I receive: a.foo.foo foo.foo False Why? I don't understand how python see the instance. Or better, does it see only the path? The classes (and the instances) are the same! Thanks for all that help me to turn the light on... Michele From __peter__ at web.de Tue Feb 8 04:36:54 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Feb 2011 10:36:54 +0100 Subject: exec, import and isinstance References: <4d510586$2@news.x-privat.org> Message-ID: Michele Petrazzo wrote: > Hi all, > I'm playing with python internals and I'm discovering a strange behavior > of isinstance. Considering the following test case: > > test/bar.py > test/b.py > test/a/__init__.py > test/a/foo.py > > -- __init__.py -> empty > > --- foo.py: > class foo: pass > c = foo > > --- b.py > def ret(): > d = {} > #s = "import sys;sys.path.append('a');import foo" ## this cause the > problem > s = "import sys;from a import foo" > exec s in d > return d["foo"].c > > --- bar.py > import a.foo > import b > > c1 = a.foo.foo > c2 = b.ret() > > print c1, c2 > print isinstance(c2(), c1) > --- > > Executing bar.py, I receive: > a.foo.foo a.foo.foo > True > > But, if I replace the indicated line, python doesn't recognize anymore > the instance and I receive: > a.foo.foo foo.foo > False > > Why? I don't understand how python see the instance. Or > better, does it see only the path? The classes (and the instances) are > the same! > > Thanks for all that help me to turn the light on... > > Michele You are importing the same module twice, once as foo and once as a.foo. To avoid importing a module that was already imported Python looks into the module cache sys.modules. If the module is already there it uses the cached version. In your case the cache contains the module, but under the key "a.foo" which Python cannot magically recognize as being the same as just "foo". Therefore the code in the module is executed twice and you get two distinct versions of every object in it. Here is a simplified demo: $ mkdir package $ touch package/__init__.py $ echo 'print "importing", __name__' > package/module.py $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append("package") >>> from package import module importing package.module >>> import module importing module Conclusion: never allow a path in sys.path that leads into a package. Also, never import the main script; again you'll get two versions of the contents, this time filed in the cache under the script's filename and under "__main__". Peter From vsapre80 at gmail.com Tue Feb 8 04:39:28 2011 From: vsapre80 at gmail.com (Vishal) Date: Tue, 8 Feb 2011 01:39:28 -0800 (PST) Subject: Idea for removing the GIL... Message-ID: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Hello, This might sound crazy..and dont know if its even possible, but... Is it possible that the Python process, creates copies of the interpreter for each thread that is launched, and some how the thread is bound to its own interpreter ? This will increase the python process size...for sure, however data sharing will remain just like it is in threads. and it "may" also allow the two threads to run in parallel, assuming the processors of today can send independent instructions from the same process to multiple cores? Comments, suggestions, brush offs are welcome :)) I heard that this has been tried before...any info about that? Thanks and best regards, Vishal Sapre From przemolicc at poczta.fm Tue Feb 8 05:00:27 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Tue, 8 Feb 2011 11:00:27 +0100 Subject: [python-list] - what do you think ? Message-ID: <20110208100026.GA6094@host.pgf.com.pl> Hello, I have just subscribed to this python-list@ and this is my N list. Usually many mailing lists use square brackets to identify its name when you have e-mails from different forums. Would you consider adding [] to this list also ? Please compare both version below: 5350 Feb 07 Richard Holmes ( 20) PIL Open Problem 5351 N Feb 07 Corey Richardson ( 17) ??> 5352 N Feb 08 Ben Finney ( 28) ??> 5376 N Feb 07 Collins, Kevin [BEELINE] ( 35) Re: [rhelv5-list] ext4 options 5385 N Feb 07 Bob Friesenhahn ( 22) Re: [zfs-discuss] ZFS and TRIM - No need for TRIM 5386 N Feb 07 Eric D. Mudama ( 25) ??> 5387 N Feb 07 Nevins Duret ( 215) [Tutor] Converting From Unicode to ASCII!! 5388 N Feb 08 David Hutto ( 138) ??> 5389 N Feb 08 David Hutto ( 7) ??> 5390 N Feb 08 David Hutto ( 9) ??> 5391 N Feb 08 Mr. Bean ( 9) Somehing interesting 5392 N Feb 08 Mr. Bean ( 9) ??> 5393 N Feb 07 nguytom ( 11) [Veritas-bu] How to use the DataDomain system cleaning process 5394 N Feb 07 David Stanaway ( 29) ??>Re: [Veritas-bu] How to use the DataDomain system cleaning process and 5350 Feb 07 Richard Holmes ( 20) [python-list] PIL Open Problem 5351 N Feb 07 Corey Richardson ( 17) ??> 5352 N Feb 08 Ben Finney ( 28) ??> 5376 N Feb 07 Collins, Kevin [BEELINE] ( 35) Re: [rhelv5-list] ext4 options 5385 N Feb 07 Bob Friesenhahn ( 22) Re: [zfs-discuss] ZFS and TRIM - No need for TRIM 5386 N Feb 07 Eric D. Mudama ( 25) ??> 5387 N Feb 07 Nevins Duret ( 215) [Tutor] Converting From Unicode to ASCII!! 5388 N Feb 08 David Hutto ( 138) ??> 5389 N Feb 08 David Hutto ( 7) ??> 5390 N Feb 08 David Hutto ( 9) ??> 5391 N Feb 08 Mr. Bean ( 9) [python-list] Somehing interesting 5392 N Feb 08 Mr. Bean ( 9) ??> 5393 N Feb 07 nguytom ( 11) [Veritas-bu] How to use the DataDomain system cleaning process 5394 N Feb 07 David Stanaway ( 29) ??>Re: [Veritas-bu] How to use the DataDomain system cleaning process Kind regards przemol 'Seamie' ---------------------------------------------------------------- Rozwiaz krzyzowke i wygraj nagrode! Sprawdz >> http://linkint.pl/f2907 From awilliam at whitemice.org Tue Feb 8 05:05:05 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 08 Feb 2011 05:05:05 -0500 Subject: Idea for removing the GIL... In-Reply-To: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: <1297159505.24148.1.camel@linux-yu4c.site> On Tue, 2011-02-08 at 01:39 -0800, Vishal wrote: > Is it possible that the Python process, creates copies of the > interpreter for each thread that is launched, and some how the thread > is bound to its own interpreter ? > and it "may" also allow the two threads to run in parallel, assuming > the processors of today can send independent instructions from the > same process to multiple cores? > Comments, suggestions, brush offs are welcome :)) Yes, it is possible, and done. See the multiprocessing module. It works very well. It isn't exactly the same as threads, but provides many similar constructs. From jeanmichel at sequans.com Tue Feb 8 05:19:16 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 08 Feb 2011 11:19:16 +0100 Subject: using attributes as defaults In-Reply-To: <1296862328.20786.7.camel@localhost.localdomain> References: <420d9aa6-38fa-48a9-8294-ed41c0891324@a28g2000prb.googlegroups.com> <1296862328.20786.7.camel@localhost.localdomain> Message-ID: <4D5118A4.8010509@sequans.com> Westley Mart?nez wrote: > On Fri, 2011-02-04 at 13:08 -0800, Wanderer wrote: >> I want to give the option of changing attributes in a method or using >> the current values of the attributes as the default. >> >> class MyClass(): >> """ my Class >> """ >> def __init__(self): >> """ initialize >> """ >> self.a = 3 >> self.b = 4 >> >> def MyMethod(self, a = self.a, b = self.b) >> """ My Method >> """ >> self.a = a >> self.b = b >> DoSomething(a, b) >> >> The above doesn't work. Is there a way to make it work? >> >> Thanks >> >> > This doesn't work because you can't reference keyword arguments in the > keyword argument array. This will work: > class MyClass: > > def __init__(self): > """ initialize > > Really? These are the worst docstrings ever. > > """ > self.a = 3 > self.b = 4 > > def MyMethod(self, a=None, b=None) > if a is not None: > self.a = a > if b is not None: > self.b = b > DoSomething(a, b) There is an alternative to this None thing: Don't use optional arguments. Optional arguments are fine ,but I found myself avoiding using them is often a better choice. Quoting the zen of python: "Explicit is better than implicit." If the reason for using optional arguments is that it'll take you 2 sec less to write the method call, then it sounds kind of wrong. Any other reason would be valid I guess. I personnaly use optional arguments only to keep backward compatibility when changing a method signature. JM From ben+python at benfinney.id.au Tue Feb 8 06:16:42 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 08 Feb 2011 22:16:42 +1100 Subject: [python-list] - what do you think ? References: Message-ID: <87vd0upyhx.fsf@benfinney.id.au> przemolicc at poczta.fm writes: > I have just subscribed to this python-list@ and this is my N list. > Usually many mailing lists use square brackets to identify its name > when you have e-mails from different forums. > Would you consider adding [] to this list also ? No thank you. Either your mail client already knows how to filter messages appropriately depending on which mailing list they came from; or, you should use a better mail client. Either way, please don't ask for the subject lines to be munged. -- \ ?I disapprove of what you say, but I will defend to the death | `\ your right to say it.? ?Evelyn Beatrice Hall, _The Friends of | _o__) Voltaire_, 1906 | Ben Finney From charles.fox at gmail.com Tue Feb 8 06:23:45 2011 From: charles.fox at gmail.com (Charles Fox (Sheffield)) Date: Tue, 8 Feb 2011 03:23:45 -0800 (PST) Subject: PDB how to define a global inspection function? Message-ID: <92522ddc-68c3-42a7-8200-042b5b920d2e@g10g2000vbv.googlegroups.com> Hi guys, I'm new to this group and have a question about debugging. I'm stepping through my code (using emacs pdbtrack and python-mode.el) and would like to isnpect objects as I go. So I've defined a little object print function, def p(obj): print obj print obj.__class__ d=dir(obj) for a in d: print a, "=", getattr(obj, a) however it only works if the function is imported by whatever module I am currently debugging. I'd like it to be available globally so I can stop and inspect anything as I step through various modules (including external libraries). Is there a way to put it in the global scope for pdb to use? Also is there a way to automatically import it whenever pdb starts up (like a matlab startup file)? (I'm not using ipython as it's not happy with pdbtrack in emacs, so am launching from emacs M- x pdb command). thanks, Charles Fox From __peter__ at web.de Tue Feb 8 06:30:55 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Feb 2011 12:30:55 +0100 Subject: [python-list] - what do you think ? References: Message-ID: przemolicc at poczta.fm wrote: > I have just subscribed to this python-list@ and this is my N list. > Usually many mailing lists use square brackets to identify its name > when you have e-mails from different forums. > Would you consider adding [] to this list also ? A better approach is to configure your email client to move mails with List-Id: into a separate folder. From __peter__ at web.de Tue Feb 8 06:37:38 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Feb 2011 12:37:38 +0100 Subject: PDB how to define a global inspection function? References: <92522ddc-68c3-42a7-8200-042b5b920d2e@g10g2000vbv.googlegroups.com> Message-ID: Charles Fox (Sheffield) wrote: > Hi guys, I'm new to this group and have a question about debugging. > I'm stepping through my code (using emacs pdbtrack and python-mode.el) > and would like to isnpect objects as I go. So I've defined a little > object print function, > > def p(obj): > print obj > print obj.__class__ > d=dir(obj) > for a in d: > print a, "=", getattr(obj, a) > > > however it only works if the function is imported by whatever module I > am currently debugging. I'd like it to be available globally so I can > stop and inspect anything as I step through various modules (including > external libraries). Is there a way to put it in the global scope for > pdb to use? Also is there a way to automatically import it whenever > pdb starts up (like a matlab startup file)? (I'm not using ipython > as it's not happy with pdbtrack in emacs, so am launching from emacs M- > x pdb command). For debugging purposes it's OK to put your function into the __builtin__ namespace: >>> def p(): print 42 ... >>> import __builtin__ >>> __builtin__.p = p Try it out: >>> with open("tmp.py", "w") as f: ... f.write("p()\n") ... >>> import tmp 42 From przemolicc at poczta.fm Tue Feb 8 07:18:50 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Tue, 8 Feb 2011 13:18:50 +0100 Subject: [python-list] - what do you think ? In-Reply-To: <87vd0upyhx.fsf@benfinney.id.au> References: <87vd0upyhx.fsf@benfinney.id.au> Message-ID: <20110208121850.GB6094@host.pgf.com.pl> On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: > przemolicc at poczta.fm writes: > > > I have just subscribed to this python-list@ and this is my N list. > > Usually many mailing lists use square brackets to identify its name > > when you have e-mails from different forums. > > Would you consider adding [] to this list also ? > > No thank you. > > Either your mail client already knows how to filter messages > appropriately depending on which mailing list they came from; or, you > should use a better mail client. mutt is quite good ;-) > Either way, please don't ask for the subject lines to be munged. Any technical reason why not ? Regards Przemek --------------------------------------------------------------- Dramatyczny wypadek Roberta Kubicy - zobacz najswiezsze doniesienia! Sprawdz >>> http://linkint.pl/f2915 From gracemia at gmail.com Tue Feb 8 07:30:18 2011 From: gracemia at gmail.com (gracemia) Date: Tue, 8 Feb 2011 04:30:18 -0800 (PST) Subject: AF_UNIX socket not supported Message-ID: <157dd3b4-abf1-4ad9-8ad6-05e87daca560@h19g2000prh.googlegroups.com> Hello ! I'm trying to develop with AF_UNIX socket type in python (2.5) but python says that AF_UNIX is not supported How can I do for work with AF_UNIX sockets? Thank you From arve.knudsen at gmail.com Tue Feb 8 07:34:31 2011 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: Tue, 8 Feb 2011 04:34:31 -0800 (PST) Subject: On Windows, how do I protect arguments to shell scripts launched with subprocess? Message-ID: Hi Since upgrading to Python 2.7, I've run into the problem that when I launch shell scripts (.e.g, *.bat) via subprocess.Popen (with False for the 'shell' option, mind you), the arguments get interpreted by the shell. For instance, the '|' character, no longer gets passed verbatim to the script. What is now the correct way to protect arguments passed as a list to subprocess.Popen? I tried enclosing each argument in double quotes, but subprocess in turn thwarts my attempt, by protecting each double quote with a backslash! For example, if I were to pass ['"|"'] as the argument list to subprocess.Popen, it'd be transformed like this: >>> subprocess.list2cmdline(['"|"']) '\\"|\\"' Thanks, Arve From vsapre80 at gmail.com Tue Feb 8 07:34:46 2011 From: vsapre80 at gmail.com (Vishal) Date: Tue, 8 Feb 2011 04:34:46 -0800 (PST) Subject: Idea for removing the GIL... References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: On Feb 8, 3:05?pm, Adam Tauno Williams wrote: > On Tue, 2011-02-08 at 01:39 -0800, Vishal wrote: > > Is it possible that the Python process, creates copies of the > > interpreter for each thread that is launched, and some how the thread > > is bound to its own interpreter ? > > and it "may" also allow the two threads to run in parallel, assuming > > the processors of today can send independent instructions from the > > same process to multiple cores? > > Comments, suggestions, brush offs ?are welcome :)) > > Yes, it is possible, and done. ?See the multiprocessing module. ?It > works very well. > > > It isn't exactly the same as threads, but provides many similar > constructs. Hi, Pardon me for my ignorance here, but 'multiprocessing' creates actual processes using fork() or CreateProcess(). I was talking of a single process, running multiple instances of the interpreter. Each thread, bound with its own interpreter. so the GIL wont be an issue anymore...each interpreter has only one thing to do, and that one thing holds the lock on its own interpreter. Since its still the same process, data sharing should happen just like in Threads. Also, multiprocessing has issues on Windows (most probably because of the way CreateProcess() functions...) Thanks and best regards, Vishal From calderone.jeanpaul at gmail.com Tue Feb 8 07:49:33 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 8 Feb 2011 04:49:33 -0800 (PST) Subject: AF_UNIX socket not supported References: <157dd3b4-abf1-4ad9-8ad6-05e87daca560@h19g2000prh.googlegroups.com> Message-ID: On Feb 8, 7:30?am, gracemia wrote: > Hello ! > > I'm trying to develop with AF_UNIX socket type in python (2.5) but > python says that AF_UNIX is not supported > How can I do for work with AF_UNIX sockets? > > Thank you Where and when does Python say this to you? http://docs.python.org/library/socket.html#socket.AF_UNIX Jean-Paul From newsmailcomp6 at gustad.com Tue Feb 8 07:51:54 2011 From: newsmailcomp6 at gustad.com (Petter Gustad) Date: Tue, 08 Feb 2011 13:51:54 +0100 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> Message-ID: <87mxm6pu39.fsf@pangea.home.gustad.com> Xah Lee writes: > problem with find xargs is that they spawn grep for each file, which > becomes too slow to be usable. find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever will call grep with a list of filenames given by find, only a single grep process will run. //Petter -- .sig removed by request. From calderone.jeanpaul at gmail.com Tue Feb 8 07:53:33 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 8 Feb 2011 04:53:33 -0800 (PST) Subject: Idea for removing the GIL... References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: <7de33303-ea0f-4a1d-b985-81fb3b315203@r13g2000yqk.googlegroups.com> On Feb 8, 7:34?am, Vishal wrote: > On Feb 8, 3:05?pm, Adam Tauno Williams wrote: > > > On Tue, 2011-02-08 at 01:39 -0800, Vishal wrote: > > > Is it possible that the Python process, creates copies of the > > > interpreter for each thread that is launched, and some how the thread > > > is bound to its own interpreter ? > > > and it "may" also allow the two threads to run in parallel, assuming > > > the processors of today can send independent instructions from the > > > same process to multiple cores? > > > Comments, suggestions, brush offs ?are welcome :)) > > > Yes, it is possible, and done. ?See the multiprocessing module. ?It > > works very well. > > > > > It isn't exactly the same as threads, but provides many similar > > constructs. > > Hi, > > Pardon me for my ignorance here, but 'multiprocessing' creates actual > processes using fork() or CreateProcess(). > I was talking of a single process, running multiple instances of the > interpreter. Each thread, bound with its own interpreter. > so the GIL wont be an issue anymore...each interpreter has only one > thing to do, and that one thing holds the lock on its own interpreter. > Since its still the same process, data sharing should happen just like > in Threads. CPython does support multiple interpreters in a single process. However, you cannot have your cake and eat it too. If you create multiple interpreters, then why do you think you'll be able to share objects between them for free? In what sense would you have *multiple* interpreters in that scenario? You will need some sort of locking between the interpreters. Then you're either back to the GIL or to some more limited form of sharing - such as you might get with the multiprocessing module. Jean-Paul From xahlee at gmail.com Tue Feb 8 07:54:05 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 8 Feb 2011 04:54:05 -0800 (PST) Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> Message-ID: hi Tass, Xah wrote: ?How to Write grep in Emacs Lisp? http://xahlee.org/emacs/elisp_grep_script.html On Feb 8, 12:22?am, Tassilo Horn wrote: > Hi Xah, > > > ? Often, the string i need to search is long, containing 300 hundred > > chars or more. You could put your search string in a file with grep, > > but it is not convenient. > > Well, you seem to encode the search string in your script, so I don't > see how that is better than relying on your shell history, which is > managed automatically, searchable, editable... not sure what you meant above. I made a mistake above. I meant to say my search string is few hundred chars. Usually a snippet of html code that may contain javascript code and also unicode chars. e.g.
> > ? grep can't really deal with directories recursively. (there's -r, > > but then you can't specify file pattern such as ?*\.html? (maybe it is > > possible, but i find it quite frustrating to trial error man page loop > > with unix tools.)) > > You can rely on shell globbing, so that grep gets a list of all files in > all subdirectories. ?For example, I can grep all header files of the > linux kernel using > > ? % grep FOO /usr/src/linux/**/*.h say, i want to search in the dir ~/web/xahlee_org/ but no more than 2 levels deep, and only files ending in ?.html?. This is not a toy question. I actually need to do that. > However, on older systems or on windows, that may produce a too long > command line. ?Alternatively, you can use the -R option to grep a > directory recursively, and specify an include globbing pattern (or many, > and/or one or many exclude patterns). > > ? % grep -R FOO --include='*.h' /usr/src/linux/ > > You can also use a combination of `find', `xargs' and `grep' (with some > complications for allowing spaces in file names [-print0 to find]), or, > when using zsh, you can use > > ? % zargs /usr/src/linux/**/*.h -- grep FOO > > which does all relevant quoting and stuff for you. problem with find xargs is that they spawn grep for each file, which becomes too slow to be usable. To not use xargs but ?find ... -exec? instead is possible of course but i always have problems with the syntax... > > ? unix grep and associated tool bag (sort, wc, uniq, pipe, sed, awk, > > ?) is not flexible. When your need is slightly more complex, unix > > shell tool bag can't handle it. For example, suppose you need to find > > a string in HTML file only if the string happens inside another tag. > > (extending the limit of unix tool bag is how Perl was born in 1987.) > > There are many things you can also do with a plain shell script. ?I'm > always amazed how good and concise you can do all sorts of file/text > manipulation using `zsh' builtins. never really got into bash for shell scripting... sometimes tried but the ratio power/syntax isn't tolerable. Knowing perl well pretty much killed any possible incentive left. ... in late 1990s, my thoughts was that i'll just learn perl well and never need to learn other lang or shell for any text processing and sys admin tasks for personal use. The thinking is that it'd be efficient in the sense of not having to waste time learning multiple langs for doing the same thing. (not counting job requirement in a company) So i have written a lot perl scripts for find & replace and file management stuff and tried to make them as general as possible. lol. But what turns out is that, over the years, for one reason or another, i just learned python, php, then in 2007 elisp. Maybe the love for languages inevitably won over my one-powerful-coherent-system efficiency obsession. But also, i end up rewrote many of my text processing script in each lang. I guess part of it is exercise when learning a new lang. ... anyway, i guess am random babbling, but one thing i learned is that for misc text processing scripts, the idea of writing a generic flexible powerful one once for all just doesn't work, because the coverage are too wide and tasks that needs to be done at one time are too specific. (and i think this makes sense, because the idea of one language or one generic script for all is mostly from ideology, not really out of practical need. If we look at the real world, it's almost always a disparate mess of components and systems.) my text processing scripts ends up being a mess. There are like several versions in different langs. A few are general, but most are basically used once or in a particular year only. (many of them do more or less the same thing). When i need to do some particular task, i found it easier just to write a new one in whatever lang that's currently in my brain memory than trying to spend time fishing out and revisit old scripts. some concrete example... e.g. i wrote this general script in 2000, intended to be one-stop for all find/replace needs ?Perl: Find ? Replace on Multiple Files? http://xahlee.org/perl-python/find_replace_perl.html in 2005, while i was learning python, i wrote (several) versions in python. e.g. ?Python: Find ? Replace Strings in Unicode Files? http://xahlee.org/perl-python/find_replace_unicode.html it's not a port of the perl code. The python version doesn't have much features as the perl. But for some reason, i have stopped using the perl version. Didn't need all that perl version features for some reason, and when i do need them, i have several other python scripts that address a particular need. (e.g. one for unicode, one for multiple pairs in one shot, one for regex one for plain text, one for find only one for finde+replace, several for find/replace only if particular condition is met, etc.) then in 2006, i fell into the emacs hole and start to learn elisp. In the process, i realized that elisp for text processing is more powerful than perl or python. Not due to lisp the lang, but more due to emacs the text-editing environment and system. I tried to explain this in few places but mostly here: ?Text Processing: Emacs Lisp vs Perl? http://xahlee.org/emacs/elisp_text_processing_lang.html so, all my new scripts for text processing are in elisp. A few of my python script i still use, but almost everything is now in elisp. also, sometimes in 2008, i grew a shell script that process weblogs using the bunch of unix bag cat grep awk sort uniq. It's about 100 lines. You can see it here: http://xahlee.org/comp/weblog_process.sh at one time i wondered, why am i doing it. Didn't i thought that perl replace all shell scripts? I gave it a little thought, and i think the conclusion is that for this task, the shell script is actually more efficient and simpler to write. Possibly if i started with perl for this task and i might end up with a good structured code and not necessarily less efficient... but you know things in life isn't all planned. It began when i just need a few lines of grep to see something in my web log. Then, over the years, added another line, another line, then another, all need based. If in any of those time i thought ?let's scratch this and restart with perl?, that'd be wasting time. Besides that, i have some doubt that perl would do a better job for this. With shell tools, each line just do one simple thing with piping. To do it in perl, one'd have to read-in the huge log file then maintain some data structure and try to parse it... too much memory and thinking would involved. If i code perl by emulating the shell code line-by-line, then it makes no sense to do it in perl, since it's just shell bag in perl. Also note, this shell script can't be replaced by elisp, because elisp is not suitable when the file size is large. well, that's my story ? extempore! ? Xah Lee From gracemia at gmail.com Tue Feb 8 08:26:33 2011 From: gracemia at gmail.com (gracemia gracemia) Date: Tue, 08 Feb 2011 13:26:33 GMT Subject: Where and when does Python say this to you? References: Message-ID: <20112882627usenet@eggheadcafe.com> File "prueba.py", line 4, in sock = socket(AF_UNIX, SOCK_STREAM) NameError: name 'AF_UNIX' is not defined code: import socket sock = socket(AF_UNIX, SOCK_STREAM) Thank you ! Submitted via EggHeadCafe Statistics, Probability, Lotteries and Dumb Programmers http://www.eggheadcafe.com/tutorials/aspnet/041de19a-e704-468f-bd3c-79164fc739f5/statistics-probability-lotteries-and-dumb-programmers.aspx From gracemia at gmail.com Tue Feb 8 08:27:39 2011 From: gracemia at gmail.com (gracemia gracemia) Date: Tue, 08 Feb 2011 13:27:39 GMT Subject: Where and when does Python say this to you? References: Message-ID: <20112882733usenet@eggheadcafe.com> This is the simple code: ---------------------------------------- import socket sock = socket(AF_UNIX, SOCK_STREAM) ------------------------------------------ Thank you Submitted via EggHeadCafe SQL Server CLR Stored Procedures for External Access http://www.eggheadcafe.com/tutorials/aspnet/08c40d08-af4a-41f6-9352-91ac82b90078/sql-server-clr-stored-procedures-for-external-access.aspx From gracemia at gmail.com Tue Feb 8 08:28:31 2011 From: gracemia at gmail.com (gracemia gracemia) Date: Tue, 08 Feb 2011 13:28:31 GMT Subject: Where and when does Python say this to you? References: Message-ID: <20112882825usenet@eggheadcafe.com> this is the simple code: -------------------------------------------------- import socket # Create an unbound and not-connected socket. sock = socket(AF_UNIX, SOCK_STREAM) --------------------------------------------------- Thank you ! Submitted via EggHeadCafe SharePoint Tip / Thought of the Day WebPart http://www.eggheadcafe.com/tutorials/aspnet/14280ff8-3c9f-46bd-8214-9267e613c8ec/sharepoint-tip--thought-of-the-day-webpart.aspx From __peter__ at web.de Tue Feb 8 08:38:01 2011 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Feb 2011 14:38:01 +0100 Subject: Where and when does Python say this to you? References: <20112882627usenet@eggheadcafe.com> Message-ID: gracemia gracemia wrote: > File "prueba.py", line 4, in > sock = socket(AF_UNIX, SOCK_STREAM) > NameError: name 'AF_UNIX' is not defined > > code: > > import socket > sock = socket(AF_UNIX, SOCK_STREAM) You need to qualify the variable names with the module name: import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) Have you worked through the tutorial http://docs.python.org/tutorial/index.html already? From benjamin.kaplan at case.edu Tue Feb 8 08:39:22 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 8 Feb 2011 08:39:22 -0500 Subject: Where and when does Python say this to you? In-Reply-To: <20112882733usenet@eggheadcafe.com> References: <20112882733usenet@eggheadcafe.com> Message-ID: On Tue, Feb 8, 2011 at 8:27 AM, gracemia gracemia wrote: > This is the simple code: > > ---------------------------------------- > import socket > > sock = socket(AF_UNIX, SOCK_STREAM) > ------------------------------------------ > > Thank you I think you're having a bit of trouble with Python's namespaces. doing "import socket" does not give you all of the socket module's stuff in your current namespace. For that, you do "from socket import *", but that's bad form because you can end up clobbering a lot of stuff. There's two ways to do it: import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) from socket import socket, AF_UNIX, SOCK_STREAM sock = socket(AF_UNIX, SOCK_STREAM) > > Submitted via EggHeadCafe > SQL Server CLR Stored Procedures for External Access > http://www.eggheadcafe.com/tutorials/aspnet/08c40d08-af4a-41f6-9352-91ac82b90078/sql-server-clr-stored-procedures-for-external-access.aspx > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Tue Feb 8 08:40:25 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 8 Feb 2011 05:40:25 -0800 Subject: Where and when does Python say this to you? In-Reply-To: <20112882627usenet@eggheadcafe.com> References: <20112882627usenet@eggheadcafe.com> Message-ID: On Tue, Feb 8, 2011 at 5:26 AM, gracemia gracemia wrote: > ?File "prueba.py", line 4, in > ? ?sock = socket(AF_UNIX, SOCK_STREAM) > NameError: name 'AF_UNIX' is not defined > > code: > > import socket > sock = socket(AF_UNIX, SOCK_STREAM) You need to qualify all those names. Normal `import` doesn't dump all the importee's names into the importer's namespace; it only imports the name of the module itself. Thus: import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) I would recommend (re-)reading the relevant part of the tutorial: http://docs.python.org/tutorial/modules.html Cheers, Chris -- I would also recommend bypassing the EggHeadCafe junk and instead posting directly to the newsgroup/mailinglist. http://blog.rebertia.com From gracemia at gmail.com Tue Feb 8 09:08:57 2011 From: gracemia at gmail.com (gracemia) Date: Tue, 8 Feb 2011 06:08:57 -0800 (PST) Subject: Where and when does Python say this to you? References: <20112882627usenet@eggheadcafe.com> Message-ID: <1a9a4271-0fb8-4629-80ff-308beb1feaf5@t13g2000vbo.googlegroups.com> On 8 feb, 14:40, Chris Rebert wrote: > On Tue, Feb 8, 2011 at 5:26 AM, gracemia gracemia wrote: > > ?File "prueba.py", line 4, in > > ? ?sock = socket(AF_UNIX, SOCK_STREAM) > > NameError: name 'AF_UNIX' is not defined > > > code: > > > import socket > > sock = socket(AF_UNIX, SOCK_STREAM) > > You need to qualify all those names. Normal `import` doesn't dump all > the importee's names into the importer's namespace; it only imports > the name of the module itself. Thus: > > import socket > sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) > > I would recommend (re-)reading the relevant part of the tutorial:http://docs.python.org/tutorial/modules.html > > Cheers, > Chris > -- > I would also recommend bypassing the EggHeadCafe junk and instead > posting directly to the newsgroup/mailinglist.http://blog.rebertia.com Sorry about my reply numbers, my browser blocked. Thank you very much. It works for me. From kentilton at gmail.com Tue Feb 8 09:52:09 2011 From: kentilton at gmail.com (kenny) Date: Tue, 8 Feb 2011 06:52:09 -0800 (PST) Subject: SunLisp III: Lisp jobs and beer in Ft Lauderdale Message-ID: <8f5a485b-a3d0-42c5-a2fb-4a6193a80e59@n16g2000prc.googlegroups.com> Come on down to the Frog & Toad for wild and crazy debates over parentheses on their own line and bring your resume -- the SunLisp core is from an up and coming Ft Lauderdale firm that is still looking for local Lisp (or Scheme or Clojure or...) talent. The pub: http://www.thefrogandtoadpub.com/ The listing: http://lispjobs.wordpress.com/ (scroll down to 22- Dec-2010) From invalid at invalid.invalid Tue Feb 8 09:54:20 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 8 Feb 2011 14:54:20 +0000 (UTC) Subject: Where and when does Python say this to you? References: <20112882627usenet@eggheadcafe.com> Message-ID: On 2011-02-08, Chris Rebert wrote: > On Tue, Feb 8, 2011 at 5:26 AM, gracemia gracemia wrote: >> ??File "prueba.py", line 4, in >> ?? ??sock = socket(AF_UNIX, SOCK_STREAM) >> NameError: name 'AF_UNIX' is not defined >> >> code: >> >> import socket >> sock = socket(AF_UNIX, SOCK_STREAM) > > You need to qualify all those names. Normal `import` doesn't dump all > the importee's names into the importer's namespace; Unfortunately, it's somewhat common for example code in various places to show the above usage (where somebody did a "from import *). IIRC there used to be examples like that even in the official docs, but I haven't seen any there in a while. But examples that look like that are still pretty easy to stumble across using Google. I'm guessing he copied the code from a "tutorial" example like this: http://www.evolt.org/node/60276 -- Grant Edwards grant.b.edwards Yow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, gmail.com hubub, hubub, hubub. From ricli85 at gmail.com Tue Feb 8 10:57:47 2011 From: ricli85 at gmail.com (Rickard Lindberg) Date: Tue, 8 Feb 2011 16:57:47 +0100 Subject: Unicode error in sax parser Message-ID: Hi, Here is a bash script to reproduce my error: #!/bin/sh cat > ?.timeline < 0.13.0devb38ace0a572b+ 2011-02-01 00:00:00 2011-02-03 08:46:00 asdsd 2011-01-24 16:38:11 2011-02-23 16:38:11 EOF python < References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: On Tue, Feb 8, 2011 at 06:34, Vishal wrote: > Also, multiprocessing has issues on Windows (most probably because of > the way CreateProcess() functions...) Such as? -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Feb 8 11:38:20 2011 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 08 Feb 2011 10:38:20 -0600 Subject: Idea for removing the GIL... In-Reply-To: References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: On 2/8/11 10:11 AM, Brian Curtin wrote: > On Tue, Feb 8, 2011 at 06:34, Vishal > wrote: > > Also, multiprocessing has issues on Windows (most probably because of > the way CreateProcess() functions...) > > Such as? Unlike a UNIX fork, CreateProcess() does not have the same copy-on-write semantics for initializing the memory of the new process. If you want to pass data to the children, the data must be pickled and sent across the process boundary. He's not saying that multiprocessing isn't useful at all on Windows, just less useful for the scenarios he is considering here. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From clp2 at rebertia.com Tue Feb 8 11:41:08 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 8 Feb 2011 08:41:08 -0800 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: On Tue, Feb 8, 2011 at 7:57 AM, Rickard Lindberg wrote: > Hi, > > Here is a bash script to reproduce my error: Including the error message and traceback is still helpful, for future reference. > ? ?#!/bin/sh > > ? ?cat > ?.timeline < > ? ?EOF > > ? ?python < ? ?# encoding: utf-8 > ? ?from xml.sax import parse > ? ?from xml.sax.handler import ContentHandler > ? ?parse(u"?.timeline", ContentHandler()) > ? ?EOF > > If I instead do > > ? ?parse(u"?.timeline".encode("utf-8"), ContentHandler()) > > the script runs without errors. > > Is this a bug or expected behavior? Bug; open() figures out the filesystem encoding just fine. Bug tracker to report the issue to: http://bugs.python.org/ Workaround: parse(open(u"?.timeline", 'r'), ContentHandler()) Cheers, Chris From ethan at stoneleaf.us Tue Feb 8 11:51:42 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 08 Feb 2011 08:51:42 -0800 Subject: [python-list] - what do you think ? In-Reply-To: <20110208121850.GB6094@host.pgf.com.pl> References: <87vd0upyhx.fsf@benfinney.id.au> <20110208121850.GB6094@host.pgf.com.pl> Message-ID: <4D51749E.1040402@stoneleaf.us> przemolicc at poczta.fm wrote: > On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: >>> Would you consider adding [] to this list also ? >>> >> No thank you. >> > Any technical reason why not ? Nope. Just don't care for it. For those of us who have our e-mails automatically sorted into folders, having [python-list] in the subject line would be incredibly redundant. Also, it's a waste of horizontal space. I believe you could use a mail preprocessor, like Fetchmail or Procmail, to modify your e-mails before you receive them, though. Good luck! ~Ethan~ From roy at panix.com Tue Feb 8 11:52:36 2011 From: roy at panix.com (Roy Smith) Date: Tue, 08 Feb 2011 11:52:36 -0500 Subject: Idea for removing the GIL... References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: In article , Robert Kern wrote: > Unlike a UNIX fork, CreateProcess() does not have the same copy-on-write > semantics for initializing the memory of the new process. If you want to pass > data to the children, the data must be pickled and sent across the process > boundary. He's not saying that multiprocessing isn't useful at all on > Windows, just less useful for the scenarios he is considering here. Amen, brother! I used to work on a project that had a build system which was very fork() intensive (lots of little perl and shell scripts driven by make). A full system build on a linux box took 30-60 minutes. Building the same code on windows/cygwin took about 12 hours. Identical hardware (8-core, 16 gig Dell server, or something like that). As far as we could tell, it was entirely due to how bad Windows was at process creation. From stefan_ml at behnel.de Tue Feb 8 12:00:46 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 08 Feb 2011 18:00:46 +0100 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: Rickard Lindberg, 08.02.2011 16:57: > Hi, > > Here is a bash script to reproduce my error: > > #!/bin/sh > > cat> ?.timeline< > > 0.13.0devb38ace0a572b+ > > > > > 2011-02-01 00:00:00 > 2011-02-03 08:46:00 > asdsd > > > > > 2011-01-24 16:38:11 > 2011-02-23 16:38:11 > > > > > > EOF > > python< # encoding: utf-8 > from xml.sax import parse > from xml.sax.handler import ContentHandler > parse(u"?.timeline", ContentHandler()) > EOF > > If I instead do > > parse(u"?.timeline".encode("utf-8"), ContentHandler()) > > the script runs without errors. > > Is this a bug or expected behavior? Expected behaviour. You cannot parse XML from unicode strings, especially not when the XML data explicitly declares itself as being encoded in UTF-8. Parse from a byte string instead, as you do in your fixed code. Stefan From stefan_ml at behnel.de Tue Feb 8 12:05:33 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 08 Feb 2011 18:05:33 +0100 Subject: Idea for removing the GIL... In-Reply-To: References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: Roy Smith, 08.02.2011 17:52: > Robert Kern wrote: > >> Unlike a UNIX fork, CreateProcess() does not have the same copy-on-write >> semantics for initializing the memory of the new process. If you want to pass >> data to the children, the data must be pickled and sent across the process >> boundary. He's not saying that multiprocessing isn't useful at all on >> Windows, just less useful for the scenarios he is considering here. > > Amen, brother! I used to work on a project that had a build system > which was very fork() intensive (lots of little perl and shell scripts > driven by make). A full system build on a linux box took 30-60 minutes. > Building the same code on windows/cygwin took about 12 hours. Identical > hardware (8-core, 16 gig Dell server, or something like that). > > As far as we could tell, it was entirely due to how bad Windows was at > process creation. Unlikely. Since you mention cygwin, it was likely due to the heavy lifting cygwin does in order to emulate fork() on Windows. http://www.cygwin.com/faq/faq-nochunks.html#faq.api.fork Stefan From i.sparry+un at gmail.com Tue Feb 8 12:32:05 2011 From: i.sparry+un at gmail.com (Icarus Sparry) Date: 08 Feb 2011 17:32:05 GMT Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> Message-ID: <4d517e15$0$22133$742ec2ed@news.sonic.net> On Tue, 08 Feb 2011 13:51:54 +0100, Petter Gustad wrote: > Xah Lee writes: > >> problem with find xargs is that they spawn grep for each file, which >> becomes too slow to be usable. > > find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever > > will call grep with a list of filenames given by find, only a single > grep process will run. > > //Petter This is getting off-topic for the listed newsgroups and into comp.unix.shell (although the question was originally posed in a MS windows context). The 'modern' way to do this is find . -maxdepth 2 -name '*.html' -exec grep whatever {} + The key thing which makes this 'modern' is the '+' at the end of the command, rather than '\;'. This causes find to execute the grep once per group of files, rather than once per file. From newsmailcomp6 at gustad.com Tue Feb 8 12:55:45 2011 From: newsmailcomp6 at gustad.com (Petter Gustad) Date: Tue, 08 Feb 2011 18:55:45 +0100 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: <87aai6pg0u.fsf@pangea.home.gustad.com> Icarus Sparry writes: > The 'modern' way to do this is > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + Agree, I've noticed that recent version of find have the + option. I remember in the old days the exec method was considered bad since it would fork grep for each process, so I've got used to using xargs. I always used to quote "{}" as well, but this does not seem to be required in later versions of find. In terms of the number of forks the above will be similar to xargs as they both have to make sure that they don't overflow the command length. Petter -- .sig removed by request. From tjreedy at udel.edu Tue Feb 8 13:20:48 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 Feb 2011 13:20:48 -0500 Subject: - what do you think ? In-Reply-To: <20110208121850.GB6094@host.pgf.com.pl> References: <87vd0upyhx.fsf@benfinney.id.au> <20110208121850.GB6094@host.pgf.com.pl> Message-ID: On 2/8/2011 7:18 AM, przemolicc at poczta.fm wrote: > On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: >> Either way, please don't ask for the subject lines to be munged. > > Any technical reason why not ? For one reason, python-list exchanges messages with both comp.lang.python and gmane.comp.python.general (the latter is how I read it), and newsreaders already separate messages by group. I also read pydev and a couple of sig lists via gmane, so extra headers would be noise. -- Terry Jan Reedy From tjreedy at udel.edu Tue Feb 8 13:25:16 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 08 Feb 2011 13:25:16 -0500 Subject: Where and when does Python say this to you? In-Reply-To: References: <20112882627usenet@eggheadcafe.com> Message-ID: On 2/8/2011 8:38 AM, Peter Otten wrote: > import socket > sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) If you do not like typing 'socket' so many times: import socket as so # or pick own abbreviation sock = so.socket(so.AF_UNIX, sot.SOCK_STREAM) > Have you worked through the tutorial > > http://docs.python.org/tutorial/index.html It is worth reading through more than once. -- Terry Jan Reedy From jenn.duerr at gmail.com Tue Feb 8 13:36:44 2011 From: jenn.duerr at gmail.com (noydb) Date: Tue, 8 Feb 2011 10:36:44 -0800 (PST) Subject: frequency of values in a field Message-ID: <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> I am looking for ways to go about capturing the frequency of unique values in one field in a dbf table which contains ~50k records. The values are numbers with atleast 5 digits to the right of the decimal, but I want the frequency of values to only 2 decimal places. I do have a method to do this courtesy of a provided tool in ArcGIS. Was just curious about ways to do it without arcgis sw, using just python. Saw this http://code.activestate.com/recipes/277600-one-liner-frequency-count/ using itertools. I'd be curious to see how experienced pythoners' (or not too experienced!) would go about doing this. Thanks for any snippets provided, this should be interesting and educating! From Joshua.R.English at gmail.com Tue Feb 8 13:42:23 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Tue, 8 Feb 2011 10:42:23 -0800 (PST) Subject: frequency of values in a field In-Reply-To: <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> Message-ID: <18b8aa1e-b702-4d8c-8460-73c782396e41@glegroupsg2000goo.googlegroups.com> You could try a collections.defaultdict object with an integer as the startup value: counts = collections.defaultdict(int) for thing in long_list: counts[get_last_two_digits(thing)] += 1 This assumes get_last_two_digits is the function that provides the key you want to count by. I'm not sure what you want get_last_two_digits to look like from your post, or how you would get the long_list, which is just an iterator through your records. Josh From awilliam at whitemice.org Tue Feb 8 14:07:02 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 08 Feb 2011 14:07:02 -0500 Subject: Idea for removing the GIL... In-Reply-To: References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: <1297192022.7755.12.camel@linux-yu4c.site> On Tue, 2011-02-08 at 11:52 -0500, Roy Smith wrote: > In article , > Robert Kern wrote: > > Unlike a UNIX fork, CreateProcess() does not have the same copy-on-write > > semantics for initializing the memory of the new process. If you want to pass > > data to the children, the data must be pickled and sent across the process > > boundary. He's not saying that multiprocessing isn't useful at all on > > Windows, just less useful for the scenarios he is considering here. > Amen, brother! I used to work on a project that had a build system > which was very fork() intensive (lots of little perl and shell scripts Comparing issues that are simply fork() to using "multiprocessing" is a bit of a false comparison. multiprocessing provides a fairly large set of information sharing techniques. Just-doing-a-fork isn't really using multiprocessing - fork'ing scripts isn't at all an equivalent to using threads. > As far as we could tell, it was entirely due to how bad Windows was at > process creation. Nope. If you want performance DO NOT USE cygwin. From nagle at animats.com Tue Feb 8 14:49:59 2011 From: nagle at animats.com (John Nagle) Date: Tue, 08 Feb 2011 11:49:59 -0800 Subject: Idea for removing the GIL... In-Reply-To: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: <4d519e64$0$10557$742ec2ed@news.sonic.net> On 2/8/2011 1:39 AM, Vishal wrote: > Hello, > > This might sound crazy..and dont know if its even possible, but... > > Is it possible that the Python process, creates copies of the > interpreter for each thread that is launched, and some how the thread > is bound to its own interpreter ? > > This will increase the python process size...for sure, however data > sharing will remain just like it is in threads. > > and it "may" also allow the two threads to run in parallel, assuming > the processors of today can send independent instructions from the > same process to multiple cores? Won't work. You'd have two threads updating the same shared data structures without locking. In CPython, there's a reference count shared across threads, but no locking at the object level. The real reason for the GIL, though, is to support dynamic code modification in multi-thread progrems. It's the ability to replace a function while it's being executed in another thread that's hard to do without a global lock. If it were just a data-side problem, local object locks, a lock at the allocator, and a concurrent garbage collector would work. John Nagle From pavlovevidence at gmail.com Tue Feb 8 16:20:21 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 8 Feb 2011 13:20:21 -0800 (PST) Subject: Idea for removing the GIL... References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> <4d519e64$0$10557$742ec2ed@news.sonic.net> Message-ID: On Feb 8, 11:49?am, John Nagle wrote: > ? ? The real reason for the GIL, though, is to support dynamic > code modification in multi-thread progrems. ?It's the ability > to replace a function while it's being executed in another thread > that's hard to do without a global lock. ?If it were just a data-side > problem, local object locks, a lock at the allocator, and a > concurrent garbage collector would work. I realize that you believe that Python's hyper-dynamicism is the cause of all evils in the world, but in this case you're not correct. Concurrent garbage collectors work just fine in IronPython and Jython, which are just as dynamic as CPython. I'm not sure why you think an executing function would be considered inaccessible and subject to collection. If you replace a function (code object, actually) in another thread it only deletes the reference from that namespace, references on the executing stack still exist. The real reason they never replaced the GIL is that fine-grained locking is expensive with reference counting. The only way the cost of finer-grained locking would be acceptable, then, is if they got rid of the reference counting altogether, and that was considered too drastic a change. Carl Banks From no.email at nospam.invalid Tue Feb 8 16:20:26 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 08 Feb 2011 13:20:26 -0800 Subject: frequency of values in a field References: <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> Message-ID: <7x7hdarzol.fsf@ruckus.brouhaha.com> noydb writes: > I am looking for ways to go about capturing the frequency of unique > values in one field in a dbf table which contains ~50k records. The > values are numbers with atleast 5 digits to the right of the decimal, > but I want the frequency of values to only 2 decimal places. I do > have a method to do this courtesy of a provided tool in ArcGIS. Was > just curious about ways to do it without arcgis sw, using just python. The Decimal module is pretty slow but is conceptually probably the right way to do this. With just 50k records it shouldn't be too bad. With more records you might look for a faster way. from decimal import Decimal as D from collections import defaultdict records = ['3.14159','2.71828','3.142857'] td = defaultdict(int) for x in records: td[D(x).quantize(D('0.01'))] += 1 print td > Saw this http://code.activestate.com/recipes/277600-one-liner-frequency-count/ > using itertools. That is cute but I cringe a bit at the temporary lists and the n log n algorithm. From ben+python at benfinney.id.au Tue Feb 8 16:33:57 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 09 Feb 2011 08:33:57 +1100 Subject: [python-list] - what do you think ? References: <87vd0upyhx.fsf@benfinney.id.au> Message-ID: <87r5bip5x6.fsf@benfinney.id.au> przemolicc at poczta.fm writes: > On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: > > Either way, please don't ask for the subject lines to be munged. > > Any technical reason why not ? No technical reason to my knowledge; but then, I haven't looked for one. The reason of ?don't mess with it if it isn't broken? is sufficient. -- \ ?If you ever reach total enlightenment while you're drinking a | `\ beer, I bet it makes beer shoot out your nose.? ?Jack Handey | _o__) | Ben Finney From rhodri at wildebst.demon.co.uk Tue Feb 8 17:03:39 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 08 Feb 2011 22:03:39 -0000 Subject: [python-list] - what do you think ? References: <87vd0upyhx.fsf@benfinney.id.au> Message-ID: On Tue, 08 Feb 2011 12:18:50 -0000, wrote: > On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: >> przemolicc at poczta.fm writes: >> >> > I have just subscribed to this python-list@ and this is my N list. >> > Usually many mailing lists use square brackets to identify its name >> > when you have e-mails from different forums. >> > Would you consider adding [] to this list also ? >> >> No thank you. >> >> Either your mail client already knows how to filter messages >> appropriately depending on which mailing list they came from; or, you >> should use a better mail client. > > mutt is quite good ;-) Definitely a step up from Outlook :-) >> Either way, please don't ask for the subject lines to be munged. > > Any technical reason why not ? python-list reflects and is reflected by the comp.lang.python newsgroup (and gmane, etc). People on the newsgroup side won't add [tags] for you, and won't thank you for breaking the minimal threading that can be inferred from titles if the list reflector adds stuff unexpectedly. -- Rhodri James *-* Wildebeest Herder to the Masses From invalid at invalid.invalid Tue Feb 8 17:04:44 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 8 Feb 2011 22:04:44 +0000 (UTC) Subject: [python-list] - what do you think ? References: Message-ID: On 2011-02-08, przemolicc at poczta.fm wrote: > I have just subscribed to this python-list@ and this is my N list. > Usually many mailing lists use square brackets to identify its name > when you have e-mails from different forums. > Would you consider adding [] to this list also ? Please don't. 1) It's redundant. There are already header lines to identify the fact that the message is from the python mailing list. 2) A lot of subscribers read the list in its own mailbox or newsgroup (e.g. via gmane.org), so identifying the list in the subject would just be a waste of pixels. 3) If you want to add stuff to the subject line for your own use, it's trivial with something like procmail. -- Grant Edwards grant.b.edwards Yow! LOOK!! Sullen at American teens wearing gmail.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS! From vlastimil.brom at gmail.com Tue Feb 8 17:25:43 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 8 Feb 2011 23:25:43 +0100 Subject: frequency of values in a field In-Reply-To: <7x7hdarzol.fsf@ruckus.brouhaha.com> References: <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> <7x7hdarzol.fsf@ruckus.brouhaha.com> Message-ID: 2011/2/8, Paul Rubin : > noydb writes: >> I am looking for ways to go about capturing the frequency of unique >> values in one field in a dbf table which contains ~50k records. The >> values are numbers with atleast 5 digits to the right of the decimal, >> but I want the frequency of values to only 2 decimal places. I do >> have a method to do this courtesy of a provided tool in ArcGIS. Was >> just curious about ways to do it without arcgis sw, using just python. >... > > from decimal import Decimal as D > from collections import defaultdict > > records = ['3.14159','2.71828','3.142857'] > > td = defaultdict(int) > for x in records: > td[D(x).quantize(D('0.01'))] += 1 > > print td > >>... Another variant of the above code using collections.Counter (in newer python versions); The actual frequency counting code is actually the single instantiation of the Counter from an iterable. The appropriate handling of the number values might be tweaked as needed. >>> from decimal import Decimal as D >>> from collections import Counter >>> records = ['3.14159','2.71828','3.142857'] >>> Counter(D(x).quantize(D('0.01')) for x in records) Counter({Decimal('3.14'): 2, Decimal('2.72'): 1}) >>> vbr From xahlee at gmail.com Tue Feb 8 17:30:53 2011 From: xahlee at gmail.com (Xah Lee) Date: Tue, 8 Feb 2011 14:30:53 -0800 (PST) Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: <0bad78ff-084a-414b-a5ac-f54ef8547f3e@o7g2000prn.googlegroups.com> On Feb 8, 9:32?am, Icarus Sparry wrote: > On Tue, 08 Feb 2011 13:51:54 +0100, Petter Gustad wrote: > > Xah Lee writes: > > >> problem with find xargs is that they spawn grep for each file, which > >> becomes too slow to be usable. > > > find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever > > > will call grep with a list of filenames given by find, only a single > > grep process will run. > > > //Petter > > This is getting off-topic for the listed newsgroups and into > comp.unix.shell (although the question was originally posed in a MS > windows context). > > The 'modern' way to do this is > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + > > The key thing which makes this 'modern' is the '+' at the end of the > command, rather than '\;'. This causes find to execute the grep once per > group of files, rather than once per file. Nice. When was the + introduced? Xah From daniel.eliason at excite.com Tue Feb 8 18:11:43 2011 From: daniel.eliason at excite.com (fortunatus) Date: Tue, 8 Feb 2011 15:11:43 -0800 (PST) Subject: SunLisp III: Lisp jobs and beer in Ft Lauderdale References: <8f5a485b-a3d0-42c5-a2fb-4a6193a80e59@n16g2000prc.googlegroups.com> Message-ID: Are you using your qooxlisp thingy? From tms at zeetix.com Tue Feb 8 18:57:33 2011 From: tms at zeetix.com (Tom Stambaugh) Date: Tue, 08 Feb 2011 18:57:33 -0500 Subject: Wing in mod_python vs wsgi? Message-ID: <4D51D86D.5070000@zeetix.com> I'm still using mod_python to deploy my framework for production (CentOS running Python 2.5.5, Apache 2.2.3, mod_python 3.3.1). I'm acutely aware of how elderly mod_python is, and I've had some frustrations using Wing to debug inside it -- at least its possible, which is not true for any other Python IDE I've tried. Does Wing do better in mod_wsgi? Is it time for me to migrate from mod_python to mod_wsgi? Has anybody tried to do this (mod_wsgi and apache) in a Windoze environment? Thx, Tom S. -- Tom Stambaugh 63 Boston Ave Somerville, MA 02144 617-776-8934 (land) 617-721-0446 (cell) From sturlamolden at yahoo.no Tue Feb 8 18:59:25 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 8 Feb 2011 15:59:25 -0800 (PST) Subject: Idea for removing the GIL... References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> Message-ID: <13b49403-e029-4abc-abfe-f3de318d1878@q36g2000yqn.googlegroups.com> On 8 Feb, 10:39, Vishal wrote: > Is it possible that the Python process, creates copies of the > interpreter for each thread that is launched, and some how the thread > is bound to its own interpreter ? In .NET lingo this is called an 'AppDomain'. This is also how tcl works -- one interpreter per thread. I once had a mock-up of that using ctypes and Python'c C API. However, the problem with 'app domains' is that OS handles are global to the process. To make OS handles private, the easiest solution is to use multiple processes, which incidentally is what the 'multiprocessing' modules does (or just os.fork if you are on Unix). Most people would not consider 'app domains' to be a true GIL-free Python, but rather think of free threading comparable to .NET, Java and C++. However, removing the GIL will do no good as long as CPython uses reference counting. Any access to reference counts must be atomic (e.g. requiring a mutex or spinlock). Here we can imagine using fine- grained locking instead of a global interpreter lock. There is a second problem, which might not be as obvious: In parallel computing there is something called 'false sharing', which in this case will be incurred on the reference counts. That is, any updating will dirty the cache lines everywhere; all processors must stop whatever they are doing to synchronize cache with RAM. This 'false sharing' will put the scalability down the drain. To make a GIL free Python, we must start by removing reference counting in favour of a generational garbage collector. That also comes with a cost. The interpreter will sometimes pause to collect garbage. The memory use will be larger as well, as garbage remain uncollected for a while and is not immediately reclaimed. Many rely on CPython because the interpreter does not pause and a Python process has a small fingerprint. If we change this, we have 'yet another Java'. There are already IronPython and Jython for those who want this. Sturla From i.sparry+un at gmail.com Tue Feb 8 19:02:17 2011 From: i.sparry+un at gmail.com (Icarus Sparry) Date: 09 Feb 2011 00:02:17 GMT Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> <0bad78ff-084a-414b-a5ac-f54ef8547f3e@o7g2000prn.googlegroups.com> Message-ID: <4d51d989$0$22142$742ec2ed@news.sonic.net> On Tue, 08 Feb 2011 14:30:53 -0800, Xah Lee wrote: > On Feb 8, 9:32?am, Icarus Sparry wrote: [snip] >> The 'modern' way to do this is >> find . -maxdepth 2 -name '*.html' -exec grep whatever {} + >> >> The key thing which makes this 'modern' is the '+' at the end of the >> command, rather than '\;'. This causes find to execute the grep once >> per group of files, rather than once per file. > > Nice. When was the + introduced? Years ago! The posix spec for find lists it in the page which has a copyright of 2001-2004. http://pubs.opengroup.org/onlinepubs/009695399/utilities/find.html Using google, I have come up with this reference from 2001 https://www.opengroup.org/sophocles/show_mail.tpl? CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=3067 in which David Korn reports writing the code in 1987. From no.email at nospam.invalid Tue Feb 8 19:12:17 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 08 Feb 2011 16:12:17 -0800 Subject: Idea for removing the GIL... References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> <13b49403-e029-4abc-abfe-f3de318d1878@q36g2000yqn.googlegroups.com> Message-ID: <7xpqr29ice.fsf@ruckus.brouhaha.com> sturlamolden writes: > comes with a cost. The interpreter will sometimes pause to collect > garbage. The memory use will be larger as well, as garbage remain > uncollected for a while and is not immediately reclaimed. Many rely on > CPython because the interpreter does not pause and a Python process > has a small fingerprint. We've had that discussion before: CPython's refcount scheme can also pause (if the last reference to a large structure is released), CPython has its own gc for cyclic structure with its own pauses, and Python is fairly memory hungry compared to plenty of small Lisp systems or even something like J2ME. Python has many nice qualities which is why I use it every day. But the refcount scheme is just an implementation hack that gets rationalized way too much. I hope PyPy abandons it. From Ross.X.Williamson.Guest at usap.gov Tue Feb 8 19:54:25 2011 From: Ross.X.Williamson.Guest at usap.gov (Williamson, Ross X. (Guest)) Date: Wed, 9 Feb 2011 13:54:25 +1300 Subject: Socket connection between python and C Message-ID: Dear All, I'm trying to implement a server/client system where the server is written in python and the client has to be written in c/c++. I can happily send simple text through the socket. Ideally I would like make say a struct (using python struct library) - and then read that in using C. Is there a better way to package data on the server in python to send down a socket to a C client? XML? Pickle? Cheers, Ross From calderone.jeanpaul at gmail.com Tue Feb 8 19:54:47 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Tue, 8 Feb 2011 16:54:47 -0800 (PST) Subject: Idea for removing the GIL... References: <7d3a67ba-b5ff-4b11-95b5-71f041dfc63a@o7g2000prn.googlegroups.com> <13b49403-e029-4abc-abfe-f3de318d1878@q36g2000yqn.googlegroups.com> <7xpqr29ice.fsf@ruckus.brouhaha.com> Message-ID: On Feb 8, 7:12?pm, Paul Rubin wrote: > But the refcount scheme is just an implementation hack > that gets rationalized way too much. ?I hope PyPy abandons it. Done. :) Jean-Paul From roy at panix.com Tue Feb 8 20:41:49 2011 From: roy at panix.com (Roy Smith) Date: Tue, 08 Feb 2011 20:41:49 -0500 Subject: Socket connection between python and C References: Message-ID: In article , "Williamson, Ross X. (Guest)" wrote: > Dear All, > > I'm trying to implement a server/client system where the server is written in > python and the client has to be written in c/c++. I can happily send simple > text through the socket. Ideally I would like make say a struct (using python > struct library) - and then read that in using C. Is there a better way to > package data on the server in python to send down a socket to a C client? > XML? Pickle? Depends on what you are trying to accomplish. If your goal is for the communication to be as efficient as possible, sending raw packed binary with the struct module on the python side, and casting the i/o buffer pointer to a struct pointer on the C/C++ side probably can't be beat. The downside is you need to worry about low-level things like padding, overflow, and endian-ness yourself. If you want to give up a little bit of efficiency in return for a huge amount of convenience, I'd go with JSON. For the kinds of things you might be thinking about using the struct module for, it's just peachy. Hugely portable (libraries for every language imaginable), easy to use, and not grossly inefficient. There's also BSON, which will be a bit more efficient at the cost of some portability. Based on your statement that you're thinking of using "struct", my guess is that XML would be overkill. From yanghatespam at gmail.com Tue Feb 8 20:59:18 2011 From: yanghatespam at gmail.com (Yang Zhang) Date: Wed, 9 Feb 2011 09:59:18 +0800 Subject: Python subprocesses experience mysterious delay in receiving stdin EOF Message-ID: I reduced a problem I was seeing in my application down into the following test case. In this code, a parent process concurrently spawns 2 (you can spawn more) subprocesses that read a big message from the parent over stdin, sleep for 5 seconds, and write something back. However, there's unexpected waiting happening somewhere, causing the code to complete in 10 seconds instead of the expected 5. If you set `verbose=True`, you can see that the straggling subprocess is receiving most of the messages, then waiting for the last chunk of 3 chars---it's not detecting that the pipe has been closed. Furthermore, if I simply don't do anything with the second process (`doreturn=True`), the first process will *never* see the EOF. Any ideas what's happening? Further down is some example output. Thanks in advance. from subprocess import * from threading import * from time import * from traceback import * import sys verbose = False doreturn = False msg = (20*4096+3)*'a' def elapsed(): return '%7.3f' % (time() - start) if sys.argv[1:]: start = float(sys.argv[2]) if verbose: for chunk in iter(lambda: sys.stdin.read(4096), ''): print >> sys.stderr, '..', time(), sys.argv[1], 'read', len(chunk) else: sys.stdin.read() print >> sys.stderr, elapsed(), '..', sys.argv[1], 'done reading' sleep(5) print msg else: start = time() def go(i): print elapsed(), i, 'starting' p = Popen(['python','stuckproc.py',str(i), str(start)], stdin=PIPE, stdout=PIPE) if doreturn and i == 1: return print elapsed(), i, 'writing' p.stdin.write(msg) print elapsed(), i, 'closing' p.stdin.close() print elapsed(), i, 'reading' p.stdout.read() print elapsed(), i, 'done' ts = [Thread(target=go, args=(i,)) for i in xrange(2)] for t in ts: t.start() for t in ts: t.join() Example output: 0.001 0 starting 0.003 1 starting 0.005 0 writing 0.016 1 writing 0.093 0 closing 0.093 0 reading 0.094 1 closing 0.094 1 reading 0.098 .. 1 done reading 5.103 1 done 5.108 .. 0 done reading 10.113 0 done -- Yang Zhang http://yz.mit.edu/ From drobinow at gmail.com Tue Feb 8 20:59:46 2011 From: drobinow at gmail.com (David Robinow) Date: Tue, 8 Feb 2011 20:59:46 -0500 Subject: [python-list] - what do you think ? In-Reply-To: References: <87vd0upyhx.fsf@benfinney.id.au> Message-ID: On Tue, Feb 8, 2011 at 5:03 PM, Rhodri James wrote: > On Tue, 08 Feb 2011 12:18:50 -0000, wrote: >> On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: >>> Either your mail client already knows how to filter messages >>> appropriately depending on which mailing list they came from; or, you >>> should use a better mail client. >> >> mutt is quite good ;-) > > Definitely a step up from Outlook :-) Not sure what your beef with Outlook is, but it does know how to filter messages appropriately. [I've never used mutt.] From rhodri at wildebst.demon.co.uk Tue Feb 8 21:12:19 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 09 Feb 2011 02:12:19 -0000 Subject: [python-list] - what do you think ? References: <87vd0upyhx.fsf@benfinney.id.au> Message-ID: On Wed, 09 Feb 2011 01:59:46 -0000, David Robinow wrote: > On Tue, Feb 8, 2011 at 5:03 PM, Rhodri James > wrote: >> On Tue, 08 Feb 2011 12:18:50 -0000, wrote: >>> On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: >>>> Either your mail client already knows how to filter messages >>>> appropriately depending on which mailing list they came from; or, you >>>> should use a better mail client. >>> >>> mutt is quite good ;-) >> >> Definitely a step up from Outlook :-) > Not sure what your beef with Outlook is, but it does know how to > filter messages appropriately. > [I've never used mutt.] Nor have I, but according to the manual it can handle mailing lists perfectly well. mutt has been around for a while. -- Rhodri James *-* Wildebeest Herder to the Masses From drsalists at gmail.com Tue Feb 8 21:15:25 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 8 Feb 2011 18:15:25 -0800 Subject: Socket connection between python and C In-Reply-To: References: Message-ID: On Tue, Feb 8, 2011 at 5:41 PM, Roy Smith wrote: > In article , > ?"Williamson, Ross X. (Guest)" > ?wrote: > >> Dear All, >> >> I'm trying to implement a server/client system where the server is written in >> python and the client has to be written in c/c++. ?I can happily send simple >> text through the socket. Ideally I would like make say a struct (using python >> struct library) - and then read that in using C. Is there a better way to >> package data on the server in python to send down a socket to a C client? >> XML? Pickle? > > Depends on what you are trying to accomplish. > > If your goal is for the communication to be as efficient as possible, > sending raw packed binary with the struct module on the python side, and > casting the i/o buffer pointer to a struct pointer on the C/C++ side > probably can't be beat. ?The downside is you need to worry about > low-level things like padding, overflow, and endian-ness yourself. Yes, this is fast, and yes, this likely won't be a good long-term option if you envision someday using even slightly exotic (or new) hardware - even using a different compiler on the same hardware could lead to troubles with this approach. However, socket.htons and related functions are a pretty good (and somewhat similar, though without most of the problems) option. > If you want to give up a little bit of efficiency in return for a huge > amount of convenience, I'd go with JSON. ?For the kinds of things you > might be thinking about using the struct module for, it's just peachy. > Hugely portable (libraries for every language imaginable), easy to use, > and not grossly inefficient. ?There's also BSON, which will be a bit > more efficient at the cost of some portability. JSON's cool. > Based on your statement that you're thinking of using "struct", my guess > is that XML would be overkill. Yes, XML's a bit more heavyweight than JSON. Also, if your data need not ever become hierarchical (which is another architectural choice that could paint you into a corner a bit), or you are prepared to add framing to your protocol if/when the time comes, you can just use ASCII. This has the benefit of allowing you to test your server with telnet. Actually, JSON and XML should preserve telnet-based server testing as well, at least to some extent - you might have to cut and paste your tests more though. From kushal.kumaran+python at gmail.com Tue Feb 8 21:37:38 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 09 Feb 2011 08:07:38 +0530 Subject: [python-list] - what do you think ? In-Reply-To: References: Message-ID: <1297219058.20501.2.camel@Nokia-N900> ----- Original message ----- > On 2011-02-08, przemolicc at poczta.fm wrote: > > > I have just subscribed to this python-list@ and this is my N list. > > Usually many mailing lists use square brackets to identify its name > > when you have e-mails from different forums. > > Would you consider adding [] to this list also ? > > Please don't. > >? 1) It's redundant.? There are already header lines to identify the >? ? ? ? fact that the message is from the python mailing list. > >? 2) A lot of subscribers read the list in its own mailbox or newsgroup >? ? ? ? (e.g. via gmane.org), so identifying the list in the subject would >? ? ? ? just be a waste of pixels. > >? 3) If you want to add stuff to the subject line for your own use, >? ? ? ? it's trivial with something like procmail. >? ? ? ? 4) Some of us like to read email on our phones and like to use the limited horizontal space for actual content. -- regards, kushal From python at mrabarnett.plus.com Tue Feb 8 22:01:18 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 Feb 2011 03:01:18 +0000 Subject: Python subprocesses experience mysterious delay in receiving stdin EOF In-Reply-To: References: Message-ID: <4D52037E.4000809@mrabarnett.plus.com> On 09/02/2011 01:59, Yang Zhang wrote: > I reduced a problem I was seeing in my application down into the > following test case. In this code, a parent process concurrently > spawns 2 (you can spawn more) subprocesses that read a big message > from the parent over stdin, sleep for 5 seconds, and write something > back. However, there's unexpected waiting happening somewhere, causing > the code to complete in 10 seconds instead of the expected 5. > > If you set `verbose=True`, you can see that the straggling subprocess > is receiving most of the messages, then waiting for the last chunk of > 3 chars---it's not detecting that the pipe has been closed. > Furthermore, if I simply don't do anything with the second process > (`doreturn=True`), the first process will *never* see the EOF. > > Any ideas what's happening? Further down is some example output. > Thanks in advance. > > from subprocess import * > from threading import * > from time import * > from traceback import * > import sys > verbose = False > doreturn = False > msg = (20*4096+3)*'a' > def elapsed(): return '%7.3f' % (time() - start) > if sys.argv[1:]: > start = float(sys.argv[2]) > if verbose: > for chunk in iter(lambda: sys.stdin.read(4096), ''): > print>> sys.stderr, '..', time(), sys.argv[1], 'read', len(chunk) > else: > sys.stdin.read() > print>> sys.stderr, elapsed(), '..', sys.argv[1], 'done reading' > sleep(5) > print msg > else: > start = time() > def go(i): > print elapsed(), i, 'starting' > p = Popen(['python','stuckproc.py',str(i), str(start)], > stdin=PIPE, stdout=PIPE) > if doreturn and i == 1: return > print elapsed(), i, 'writing' > p.stdin.write(msg) > print elapsed(), i, 'closing' > p.stdin.close() > print elapsed(), i, 'reading' > p.stdout.read() > print elapsed(), i, 'done' > ts = [Thread(target=go, args=(i,)) for i in xrange(2)] > for t in ts: t.start() > for t in ts: t.join() > > Example output: > > 0.001 0 starting > 0.003 1 starting > 0.005 0 writing > 0.016 1 writing > 0.093 0 closing > 0.093 0 reading > 0.094 1 closing > 0.094 1 reading > 0.098 .. 1 done reading > 5.103 1 done > 5.108 .. 0 done reading > 10.113 0 done > I changed 'python' to the path of python.exe and 'stuckproc.py' to its full path and tried it with Python 2.7 on Windows XP Pro. It worked as expected. From vivshrivastava at gmail.com Tue Feb 8 23:00:11 2011 From: vivshrivastava at gmail.com (Vivek Shrivastava) Date: Tue, 8 Feb 2011 20:00:11 -0800 Subject: [python-list] - what do you think ? In-Reply-To: References: <87vd0upyhx.fsf@benfinney.id.au> Message-ID: I think that will help people like me who just depend on gmail, and I know there are various ways to do filtering in gmail, but just addition of the tag in [ ] will help avoiding those.. I kindly second that... On Tue, Feb 8, 2011 at 6:12 PM, Rhodri James wrote: > On Wed, 09 Feb 2011 01:59:46 -0000, David Robinow > wrote: > > On Tue, Feb 8, 2011 at 5:03 PM, Rhodri James >> wrote: >> >>> On Tue, 08 Feb 2011 12:18:50 -0000, wrote: >>> >>>> On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: >>>> >>>>> Either your mail client already knows how to filter messages >>>>> appropriately depending on which mailing list they came from; or, you >>>>> should use a better mail client. >>>>> >>>> >>>> mutt is quite good ;-) >>>> >>> >>> Definitely a step up from Outlook :-) >>> >> Not sure what your beef with Outlook is, but it does know how to >> >> filter messages appropriately. >> [I've never used mutt.] >> > > Nor have I, but according to the manual it can handle mailing lists > perfectly well. mutt has been around for a while. > > > -- > Rhodri James *-* Wildebeest Herder to the Masses > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wdepli at mikrotec.com Tue Feb 8 23:17:49 2011 From: wdepli at mikrotec.com (Doug Epling) Date: Tue, 08 Feb 2011 23:17:49 -0500 Subject: Wing in mod_python vs wsgi? In-Reply-To: References: Message-ID: I don't know about your IDE, I am using the default IDLE just because it is handy. But I have made the switch from mod_python. It was a good idea, but mod_wsgi is a better idea. And as you know, mod_python is no longer supported. I am running Apache with mod_wsgi in a windows 7 environment -- I am working on implementing Pylons. Also, I have another Apache server with mod_wsgi serving a MoinMoin wiki. This one is on a good os -- Fedora. On 2/8/2011 6:57 PM, Tom Stambaugh wrote: > I'm still using mod_python to deploy my framework for production (CentOS > running Python 2.5.5, Apache 2.2.3, mod_python 3.3.1). I'm acutely aware > of how elderly mod_python is, and I've had some frustrations using Wing > to debug inside it -- at least its possible, which is not true for any > other Python IDE I've tried. > > Does Wing do better in mod_wsgi? Is it time for me to migrate from > mod_python to mod_wsgi? > > Has anybody tried to do this (mod_wsgi and apache) in a Windoze > environment? > > Thx, > Tom S. From nobody at nowhere.com Wed Feb 9 00:24:48 2011 From: nobody at nowhere.com (Nobody) Date: Wed, 09 Feb 2011 05:24:48 +0000 Subject: Reassign or discard Popen().stdout from a server process References: Message-ID: On Fri, 04 Feb 2011 15:48:55 +0000, John O'Hagan wrote: > But I'm still a little curious as to why even unsuccessfully attempting to > reassign stdout seems to stop the pipe buffer from filling up. It doesn't. If the server continues to run, then it's ignoring/handling both SIGPIPE and the EPIPE error. Either that, or another process has the read end of the pipe open (so no SIGPIPE/EPIPE), and the server is using non-blocking I/O or select() so that it doesn't block writing its diagnostic messages. From mandersonrandersonanderson at gmail.com Wed Feb 9 00:52:28 2011 From: mandersonrandersonanderson at gmail.com (Nanderson) Date: Tue, 8 Feb 2011 21:52:28 -0800 (PST) Subject: Easy function, please help. Message-ID: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> def num_digits(n): count = 0 while n: count = count + 1 n = n / 10 return count This is a function that basically says how many digits are in a number. For example, >>>print num_digits(44) 2 >>>print num_digits(7654) 4 This function counts the number of decimal digits in a positive integer expressed in decimal format. I get this function ALMOST completely. The only thing I don't understand is why it eventually exits the loop, and goes off to the second branch. "while n" is confusing me. What I am thinking is that if someone puts "while n" the loop would be infinite. I get what is happening in the function, and I understand why this would work, but for some reason it's confusing me as to how it is exiting the loop after a certain number of times. Help is appreciated, thanks. From mhrivnak at hrivnak.org Wed Feb 9 01:29:33 2011 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Wed, 9 Feb 2011 01:29:33 -0500 Subject: Easy function, please help. In-Reply-To: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> Message-ID: Your function only works if n is an integer. Example: >>> num_digits(234) 3 >>> num_digits(23.4) 325 When doing integer division, python will throw away the remainder and return an int. Using your example of n==44, 44/10 == 4 and 4/10 == 0 Before each iteration of the while loop, the given expression (in this case just n) is evaluated as a boolean. Your function would act the same if it looked like this: def num_digits(n): count = 0 while bool(n): count = count + 1 n = n / 10 return count 0 of course evaluates to False as a boolean, which is why the while loop stops. Just for kicks, this function would work about as well: def num_digits(n): return len(str(n)) And if either of these were a real function you planned to use, you'd probably want to either cast n as an int ( int(n) ) or at least check its type: if not isinstance(n, int): raise TypeError("WTF you didn't pass me an int") Michael On Wed, Feb 9, 2011 at 12:52 AM, Nanderson wrote: > def num_digits(n): > ? ?count = 0 > ? ?while n: > ? ? ? ?count = count + 1 > ? ? ? ?n = n / 10 > ? ?return count > > This is a function that basically says how many digits are in a > number. For example, >>>>print num_digits(44) > 2 >>>>print num_digits(7654) > 4 > > This function counts the number of decimal digits in a positive > integer expressed in decimal format. I get this function ALMOST > completely. The only thing I don't understand is why it eventually > exits the loop, and goes off to the second branch. "while n" is > confusing me. What I am thinking is that if someone puts "while n" the > loop would be infinite. I get what is happening in the function, and I > understand why this would work, but for some reason it's confusing me > as to how it is exiting the loop after a certain number of times. Help > is appreciated, thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > From mandersonrandersonanderson at gmail.com Wed Feb 9 01:36:46 2011 From: mandersonrandersonanderson at gmail.com (Nanderson) Date: Tue, 8 Feb 2011 22:36:46 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> Message-ID: <077a7b0d-5ea9-4f09-bc22-83785e49525e@1g2000pro.googlegroups.com> On Feb 8, 10:29?pm, Michael Hrivnak wrote: > Your function only works if n is an integer. ?Example: > > >>> num_digits(234) > 3 > >>> num_digits(23.4) > > 325 > > When doing integer division, python will throw away the remainder and > return an int. ?Using your example of n==44, 44/10 == 4 and 4/10 == 0 > > Before each iteration of the while loop, the given expression (in this > case just n) is evaluated as a boolean. ?Your function would act the > same if it looked like this: > > def num_digits(n): > ? count = 0 > ? while bool(n): > ? ? ? count = count + 1 > ? ? ? n = n / 10 > ? return count > > 0 of course evaluates to False as a boolean, which is why the while loop stops. > > Just for kicks, this function would work about as well: > > def num_digits(n): > ? ?return len(str(n)) > > And if either of these were a real function you planned to use, you'd > probably want to either cast n as an int ( int(n) ) or at least check > its type: > > if not isinstance(n, int): > ? ?raise TypeError("WTF you didn't pass me an int") > > Michael > > On Wed, Feb 9, 2011 at 12:52 AM, Nanderson > > > > > > > > wrote: > > def num_digits(n): > > ? ?count = 0 > > ? ?while n: > > ? ? ? ?count = count + 1 > > ? ? ? ?n = n / 10 > > ? ?return count > > > This is a function that basically says how many digits are in a > > number. For example, > >>>>print num_digits(44) > > 2 > >>>>print num_digits(7654) > > 4 > > > This function counts the number of decimal digits in a positive > > integer expressed in decimal format. I get this function ALMOST > > completely. The only thing I don't understand is why it eventually > > exits the loop, and goes off to the second branch. "while n" is > > confusing me. What I am thinking is that if someone puts "while n" the > > loop would be infinite. I get what is happening in the function, and I > > understand why this would work, but for some reason it's confusing me > > as to how it is exiting the loop after a certain number of times. Help > > is appreciated, thanks. > > -- > >http://mail.python.org/mailman/listinfo/python-list Ah, thank you very much! I forgot completely about how python does division, do this confused me quite a bit. Thanks for the help, and the only reason I wrote the function this way is because I'm learning to program, and I'm try to do the exercises of the tutorial I'm reading. It really is for learning purposes. Thanks again! From paul.nospam at rudin.co.uk Wed Feb 9 02:08:57 2011 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 09 Feb 2011 07:08:57 +0000 Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> Message-ID: <87oc6l8z1y.fsf@rudin.co.uk> Nanderson writes: > loop would be infinite. I get what is happening in the function, and I > understand why this would work, but for some reason it's confusing me > as to how it is exiting the loop after a certain number of times. Help > is appreciated, thanks. It works because 0 tests false and because integer division yields integers... eventually you'll get something like 1/10 giving 0. It's not necessarily a good thing to rely on. For example if you try it after "from __future__ import division" - or in python 3 - you'll get a float as the result of the division and it won't test False. From dvicente at full-on-net.com Wed Feb 9 02:23:39 2011 From: dvicente at full-on-net.com (David Vicente) Date: Wed, 9 Feb 2011 08:23:39 +0100 Subject: Remove whitespaces and line breaks in a XML file In-Reply-To: <9de1ca25-550d-4591-8255-c07d3e5e7b15@glegroupsg2000goo.googlegroups.com> References: <9de1ca25-550d-4591-8255-c07d3e5e7b15@glegroupsg2000goo.googlegroups.com> Message-ID: <000601cbc82a$5486c090$fd9441b0$@com> I?ll try to mix it with my code (xml.etree). Thanks ;) -----Mensaje original----- De: python-list-bounces+dvicente=full-on-net.com at python.org [mailto:python-list-bounces+dvicente=full-on-net.com at python.org] En nombre de Josh English Enviado el: martes, 08 de febrero de 2011 0:46 Para: python-list at python.org CC: python-list at python.org Asunto: Re: Remove whitespaces and line breaks in a XML file I found the code posted at http://infix.se/2007/02/06/gentlemen-indent-your-xml quite helpful in turning my xml into human-readable structures. It works best for XML-Data. Josh -- http://mail.python.org/mailman/listinfo/python-list From ricli85 at gmail.com Wed Feb 9 03:32:14 2011 From: ricli85 at gmail.com (Rickard Lindberg) Date: Wed, 9 Feb 2011 09:32:14 +0100 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: >> Here is a bash script to reproduce my error: > > Including the error message and traceback is still helpful, for future > reference. Thanks for pointing it out. >> ? ?#!/bin/sh >> >> ? ?cat > ?.timeline < >> ? ?EOF >> >> ? ?python <> ? ?# encoding: utf-8 >> ? ?from xml.sax import parse >> ? ?from xml.sax.handler import ContentHandler >> ? ?parse(u"?.timeline", ContentHandler()) >> ? ?EOF >> >> If I instead do >> >> ? ?parse(u"?.timeline".encode("utf-8"), ContentHandler()) >> >> the script runs without errors. >> >> Is this a bug or expected behavior? > > Bug; open() figures out the filesystem encoding just fine. > Bug tracker to report the issue to: http://bugs.python.org/ > > Workaround: > parse(open(u"?.timeline", 'r'), ContentHandler()) When I tried your workaround, I still got this error: Traceback (most recent call last): File "", line 4, in File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/__init__.py", line 31, in parse parser.parse(filename_or_stream) File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/expatreader.py", line 109, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/xmlreader.py", line 119, in parse self.prepareParser(source) File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/expatreader.py", line 121, in prepareParser self._parser.SetBase(source.getSystemId()) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 0: ordinal not in range(128) The open(..) part works fine, but there still seems to be a problem inside the sax parser. -- Rickard Lindberg From me+list/python at ixokai.io Wed Feb 9 03:36:49 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 09 Feb 2011 00:36:49 -0800 Subject: [python-list] - what do you think ? In-Reply-To: References: <87vd0upyhx.fsf@benfinney.id.au> Message-ID: <4D525221.6030405@ixokai.io> On 2/8/11 8:00 PM, Vivek Shrivastava wrote: > I think that will help people like me who just depend on gmail, and I > know there are various ways to do filtering in gmail, but just addition > of the tag in [ ] will help avoiding those.. I kindly second that.. .. yeah, no. Let's not screw up everyone's life to help those who are using _Gmail_ who don't want to take advantage of Gmail's capability to PERFECTLY filter the group into a folder without it. You /just/ depend on Gmail? You want to infringe on everyone else so... you can... _avoid_ er, using your client to sort your mails into a folder/label? Gee, thanks, no. Click on this message. There's this "Show Details" button that appears at the top of it. Click that. Then there's this line that says "mailing list", followed by "python-list.python.org" Then there's this super easy link added right next that you can click. Voila, it fills out everything you need have just Gmail, depend just on Gmail, and sort your messages in a very usable way, without screwing with everyone else and stealing away their valuable horizontal space. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From stefan_ml at behnel.de Wed Feb 9 03:58:19 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 09 Feb 2011 09:58:19 +0100 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: Rickard Lindberg, 09.02.2011 09:32: > On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: >>> Here is a bash script to reproduce my error: >> >> Including the error message and traceback is still helpful, for future >> reference. > > Thanks for pointing it out. > >>> #!/bin/sh >>> >>> cat> ?.timeline<> >>> EOF >>> >>> python<>> # encoding: utf-8 >>> from xml.sax import parse >>> from xml.sax.handler import ContentHandler >>> parse(u"?.timeline", ContentHandler()) >>> EOF >>> >>> If I instead do >>> >>> parse(u"?.timeline".encode("utf-8"), ContentHandler()) >>> >>> the script runs without errors. >>> >>> Is this a bug or expected behavior? >> >> Bug; open() figures out the filesystem encoding just fine. >> Bug tracker to report the issue to: http://bugs.python.org/ >> >> Workaround: >> parse(open(u"?.timeline", 'r'), ContentHandler()) > > When I tried your workaround, I still got this error: > > Traceback (most recent call last): > File "", line 4, in > File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/__init__.py", > line 31, in parse > parser.parse(filename_or_stream) > File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/expatreader.py", > line 109, in parse > xmlreader.IncrementalParser.parse(self, source) > File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/xmlreader.py", > line 119, in parse > self.prepareParser(source) > File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/expatreader.py", > line 121, in prepareParser > self._parser.SetBase(source.getSystemId()) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in > position 0: ordinal not in range(128) > > The open(..) part works fine, but there still seems to be a problem inside the > sax parser. Did you read my reply? Stefan From stefan_ml at behnel.de Wed Feb 9 04:14:58 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 09 Feb 2011 10:14:58 +0100 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: Stefan Behnel, 09.02.2011 09:58: > Rickard Lindberg, 09.02.2011 09:32: >> On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: >>>> Here is a bash script to reproduce my error: >>> >>> Including the error message and traceback is still helpful, for future >>> reference. >> >> Thanks for pointing it out. >> >>>> #!/bin/sh >>>> >>>> cat> ?.timeline<>> >>>> EOF >>>> >>>> python<>>> # encoding: utf-8 >>>> from xml.sax import parse >>>> from xml.sax.handler import ContentHandler >>>> parse(u"?.timeline", ContentHandler()) >>>> EOF >>>> >>>> If I instead do >>>> >>>> parse(u"?.timeline".encode("utf-8"), ContentHandler()) >>>> >>>> the script runs without errors. >>>> >>>> Is this a bug or expected behavior? >>> >>> Bug; open() figures out the filesystem encoding just fine. >>> Bug tracker to report the issue to: http://bugs.python.org/ >>> >>> Workaround: >>> parse(open(u"?.timeline", 'r'), ContentHandler()) >> >> When I tried your workaround, I still got this error: >> >> Traceback (most recent call last): >> File "", line 4, in >> File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/__init__.py", >> line 31, in parse >> parser.parse(filename_or_stream) >> File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/expatreader.py", >> line 109, in parse >> xmlreader.IncrementalParser.parse(self, source) >> File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/xmlreader.py", >> line 119, in parse >> self.prepareParser(source) >> File "/usr/lib64/python2.7/site-packages/_xmlplus/sax/expatreader.py", >> line 121, in prepareParser >> self._parser.SetBase(source.getSystemId()) >> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in >> position 0: ordinal not in range(128) >> >> The open(..) part works fine, but there still seems to be a problem >> inside the >> sax parser. > > Did you read my reply? Sorry, it was me who failed to read your question properly. Unicode file names aren't really working well, especially not in Py2.x. Python 3.2 provides many improvements here. I assume your file system encoding is UTF-8? What does sys.getfilesystemencoding() give you? Stefan From yanghatespam at gmail.com Wed Feb 9 05:11:39 2011 From: yanghatespam at gmail.com (Yang Zhang) Date: Wed, 9 Feb 2011 18:11:39 +0800 Subject: Python subprocesses experience mysterious delay in receiving stdin EOF In-Reply-To: <4D52037E.4000809@mrabarnett.plus.com> References: <4D52037E.4000809@mrabarnett.plus.com> Message-ID: On Wed, Feb 9, 2011 at 11:01 AM, MRAB wrote: > On 09/02/2011 01:59, Yang Zhang wrote: >> >> I reduced a problem I was seeing in my application down into the >> following test case. In this code, a parent process concurrently >> spawns 2 (you can spawn more) subprocesses that read a big message >> from the parent over stdin, sleep for 5 seconds, and write something >> back. However, there's unexpected waiting happening somewhere, causing >> the code to complete in 10 seconds instead of the expected 5. >> >> If you set `verbose=True`, you can see that the straggling subprocess >> is receiving most of the messages, then waiting for the last chunk of >> 3 chars---it's not detecting that the pipe has been closed. >> Furthermore, if I simply don't do anything with the second process >> (`doreturn=True`), the first process will *never* see the EOF. >> >> Any ideas what's happening? Further down is some example output. >> Thanks in advance. >> >> ? ? from subprocess import * >> ? ? from threading import * >> ? ? from time import * >> ? ? from traceback import * >> ? ? import sys >> ? ? verbose = False >> ? ? doreturn = False >> ? ? msg = (20*4096+3)*'a' >> ? ? def elapsed(): return '%7.3f' % (time() - start) >> ? ? if sys.argv[1:]: >> ? ? ? start = float(sys.argv[2]) >> ? ? ? if verbose: >> ? ? ? ? for chunk in iter(lambda: sys.stdin.read(4096), ''): >> ? ? ? ? ? print>> ?sys.stderr, '..', time(), sys.argv[1], 'read', >> len(chunk) >> ? ? ? else: >> ? ? ? ? sys.stdin.read() >> ? ? ? print>> ?sys.stderr, elapsed(), '..', sys.argv[1], 'done reading' >> ? ? ? sleep(5) >> ? ? ? print msg >> ? ? else: >> ? ? ? start = time() >> ? ? ? def go(i): >> ? ? ? ? print elapsed(), i, 'starting' >> ? ? ? ? p = Popen(['python','stuckproc.py',str(i), str(start)], >> stdin=PIPE, stdout=PIPE) >> ? ? ? ? if doreturn and i == 1: return >> ? ? ? ? print elapsed(), i, 'writing' >> ? ? ? ? p.stdin.write(msg) >> ? ? ? ? print elapsed(), i, 'closing' >> ? ? ? ? p.stdin.close() >> ? ? ? ? print elapsed(), i, 'reading' >> ? ? ? ? p.stdout.read() >> ? ? ? ? print elapsed(), i, 'done' >> ? ? ? ts = [Thread(target=go, args=(i,)) for i in xrange(2)] >> ? ? ? for t in ts: t.start() >> ? ? ? for t in ts: t.join() >> >> Example output: >> >> ? ? ? 0.001 0 starting >> ? ? ? 0.003 1 starting >> ? ? ? 0.005 0 writing >> ? ? ? 0.016 1 writing >> ? ? ? 0.093 0 closing >> ? ? ? 0.093 0 reading >> ? ? ? 0.094 1 closing >> ? ? ? 0.094 1 reading >> ? ? ? 0.098 .. 1 done reading >> ? ? ? 5.103 1 done >> ? ? ? 5.108 .. 0 done reading >> ? ? ?10.113 0 done >> > I changed 'python' to the path of python.exe and 'stuckproc.py' to its > full path and tried it with Python 2.7 on Windows XP Pro. It worked as > expected. Good point - I didn't specify that I'm seeing this on Linux (Ubuntu 10.04's Python 2.6). -- Yang Zhang http://yz.mit.edu/ From przemolicc at poczta.fm Wed Feb 9 05:40:32 2011 From: przemolicc at poczta.fm (przemolicc at poczta.fm) Date: Wed, 9 Feb 2011 11:40:32 +0100 Subject: - what do you think ? In-Reply-To: References: <87vd0upyhx.fsf@benfinney.id.au> <20110208121850.GB6094@host.pgf.com.pl> Message-ID: <20110209104031.GA9146@host.pgf.com.pl> On Tue, Feb 08, 2011 at 01:20:48PM -0500, Terry Reedy wrote: > On 2/8/2011 7:18 AM, przemolicc at poczta.fm wrote: >> On Tue, Feb 08, 2011 at 10:16:42PM +1100, Ben Finney wrote: > >>> Either way, please don't ask for the subject lines to be munged. >> >> Any technical reason why not ? > > For one reason, python-list exchanges messages with both > comp.lang.python and gmane.comp.python.general (the latter is how I read > it), and newsreaders already separate messages by group. I also read > pydev and a couple of sig lists via gmane, so extra headers would be > noise. It is important technical reason. Thank you. :-) Regards Przemek --------------------------------------------------------------- Dramatyczny wypadek Roberta Kubicy - zobacz najswiezsze doniesienia! Sprawdz >>> http://linkint.pl/f2915 From devel-bounces at lists.laptop.org Wed Feb 9 07:29:03 2011 From: devel-bounces at lists.laptop.org (devel-bounces at lists.laptop.org) Date: Wed, 09 Feb 2011 07:29:03 -0500 Subject: Your message to Devel awaits moderator approval Message-ID: Your mail to 'Devel' with the subject TEST Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: http://lists.laptop.org/confirm/devel/ca3ba2f6183fe295e024fc67445c384a58bcbecf From frank at chagford.com Wed Feb 9 07:31:46 2011 From: frank at chagford.com (Frank Millman) Date: Wed, 9 Feb 2011 14:31:46 +0200 Subject: wsgi, ajax, and multiple requests Message-ID: Hi all I have a question about wsgi. As far as I can tell from the spec and from the reference implementation, wsgi requires that each request from the client is responded to by one or more headers, followed by the response body. It is then ready to handle the next request. 99% of the time this is fine, but I have a situation where I need to vary this, and I cannot see how to do it. Here is the scenario. I am dabbling with writing an ajax-style app. On occasion, I want to send more than one message from the client to the server. It is important that the server processes the messages in the same order that they are generated. I have found that the Safari browser does not always send them in the correct sequence. I found an article on the subject - http://www.sitepen.com/blog/2009/02/27/deterministic-clientserver-interaction/ It explains that you can never guarantee that the messages will arrive in the same order, with *any* browser. Maybe I was lucky with the other ones. It goes on to say that, if the order is important, you must include a header with a sequential counter, and the server must check the sequence. If received out of sequence, it must queue the one received, wait for the correct one, and then process them both in the correct order. So the question is, how can I achieve this with wsgi? If I detect that I have received a request out of sequence, I can queue the request, and send an empty response. When I receive the correct request, I can process it, call start_response(), and return the response body, but I cannot figure out how to get back to process the queued request. Any advice will be much appreciated. Frank Millman From ricli85 at gmail.com Wed Feb 9 08:01:26 2011 From: ricli85 at gmail.com (Rickard Lindberg) Date: Wed, 9 Feb 2011 14:01:26 +0100 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: >> Did you read my reply? > >Sorry, it was me who failed to read your question properly. > >Unicode file names aren't really working well, especially not in Py2.x. >Python 3.2 provides many improvements here. > >I assume your file system encoding is UTF-8? What does >sys.getfilesystemencoding() give you? > >Stefan Since I'm not registered on the Python mailing list I had some trouble replying to your message. My getfilesystemencoding() returns utf-8. -- Rickard Lindberg From stefan_ml at behnel.de Wed Feb 9 08:20:54 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 09 Feb 2011 14:20:54 +0100 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: Rickard Lindberg, 09.02.2011 14:01: >>> Did you read my reply? >> >> Sorry, it was me who failed to read your question properly. >> >> Unicode file names aren't really working well, especially not in Py2.x. >> Python 3.2 provides many improvements here. >> >> I assume your file system encoding is UTF-8? What does >> sys.getfilesystemencoding() give you? > > My getfilesystemencoding() returns utf-8. Ok, same here. I tried it with Python 3.1.2 and it works for me. So I think the right work-around for you in Python 2 is to encode the file name using whatever "sys.getfilesystemencoding()" returns. And I agree with Chris Rebert that you should open a bug against the sax package in Python 2.7 on the bug tracker. Stefan From awilliam at whitemice.org Wed Feb 9 08:52:41 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 09 Feb 2011 08:52:41 -0500 Subject: wsgi, ajax, and multiple requests In-Reply-To: References: Message-ID: <1297259561.3827.28.camel@linux-yu4c.site> On Wed, 2011-02-09 at 14:31 +0200, Frank Millman wrote: > I am dabbling with writing an ajax-style app. On occasion, I want to send > more than one message from the client to the server. It is important that > the server processes the messages in the same order that they are generated. > I have found that the Safari browser does not always send them in the > correct sequence. > I found an article on the subject - > http://www.sitepen.com/blog/2009/02/27/deterministic-clientserver-interaction/ > It explains that you can never guarantee that the messages will arrive in > the same order, with *any* browser. Correct. > Maybe I was lucky with the other ones. > It goes on to say that, if the order is important, you must include a header > with a sequential counter, and the server must check the sequence. Yep. This is similar to the If-Match headers used by HTTP (and especially WebDAV). > So the question is, how can I achieve this with wsgi? If I detect that I > have received a request out of sequence, I can queue the request, and send > an empty response. When I receive the correct request, I can process it, > call start_response(), and return the response body, but I cannot figure out > how to get back to process the queued request. I'd simply notify the client that the request could not be processed and have the client resend; this generally works much better than trying to "hold" the request on the server [what if the next one you expect never comes? what if you hit a different server due to DNS round-robin / clustering / etc...] If order is *very* important the client should perform each operation sequentially only sending the next-step when it has confirmation the previous ones have completed. This is really a client-side issue IMO. From rbotting at csusb.edu Wed Feb 9 09:27:40 2011 From: rbotting at csusb.edu (RJB) Date: Wed, 9 Feb 2011 06:27:40 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> Message-ID: <6417e4f3-5f3b-46d5-b605-f6f18f4de177@z3g2000prz.googlegroups.com> On Feb 8, 11:08?pm, Paul Rudin wrote: > It works because 0 tests false and because integer division yields > integers... eventually you'll get something like 1/10 giving 0. > > It's not necessarily a good thing to rely on. For example if you try it > after "from __future__ import division" - or in python 3 - you'll get a > float as the result of the division and it won't test False. What operator should I use if I want integer division? Ada and Pascal used "div" if I recall rightly. From misnomer at gmail.com Wed Feb 9 09:36:07 2011 From: misnomer at gmail.com (Nicholas Devenish) Date: Wed, 09 Feb 2011 14:36:07 +0000 Subject: Easy function, please help. In-Reply-To: <6417e4f3-5f3b-46d5-b605-f6f18f4de177@z3g2000prz.googlegroups.com> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <6417e4f3-5f3b-46d5-b605-f6f18f4de177@z3g2000prz.googlegroups.com> Message-ID: On 09/02/2011 14:27, RJB wrote: > What operator should I use if I want integer division? > Ada and Pascal used "div" if I recall rightly. The operator for integer division is // From tjreedy at udel.edu Wed Feb 9 09:48:27 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 09 Feb 2011 09:48:27 -0500 Subject: Easy function, please help. In-Reply-To: <6417e4f3-5f3b-46d5-b605-f6f18f4de177@z3g2000prz.googlegroups.com> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <6417e4f3-5f3b-46d5-b605-f6f18f4de177@z3g2000prz.googlegroups.com> Message-ID: On 2/9/2011 9:27 AM, RJB wrote: > On Feb 8, 11:08 pm, Paul Rudin wrote: > >> It works because 0 tests false and because integer division yields >> integers... eventually you'll get something like 1/10 giving 0. >> >> It's not necessarily a good thing to rely on. For example if you try it >> after "from __future__ import division" - or in python 3 - you'll get a >> float as the result of the division and it won't test False. > > What operator should I use if I want integer division? // The line should be 'n = n//10' or even 'n //= 10'. You might have answered your own question be putting print(n, count) at the top of the loop body. Print is an excellent tool. -- Terry Jan Reedy From rantingrick at gmail.com Wed Feb 9 09:51:25 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 9 Feb 2011 06:51:25 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> Message-ID: On Feb 9, 1:08?am, Paul Rudin wrote: > Nanderson writes: > > loop would be infinite. I get what is happening in the function, and I > > understand why this would work, but for some reason it's confusing me > > as to how it is exiting the loop after a certain number of times. Help > > is appreciated, thanks. > > It works because 0 tests false and because integer division yields > integers... eventually you'll get something like 1/10 giving 0. It works because of a design flaw in the language! Specifically i am referring to treating the integer 0 as False and any other integers as True. There is also the empty vs non empty containers that work this way besides numeric types. ---------------------------------- Python 3.1.1 Interactive Session ---------------------------------- >>> bool(0) False >>> bool(1) True >>> bool(-1) True >>> bool(-1.0) True >>> bool(1.0) True >>> bool(0.0) False >>> bool([]) False >>> bool([1]) True Sure it *seems* like a "bright" idea at first however later you find out this sort of laziness just induces more subtle bugs in code. Python3000 fixed a lot of warts in Python2.x HOWEVER, python3000 did not go near far enough! We need more radical changes (and when i say radical i mean removing poorly thought out design patterns like this "boolean emulation"!) to the language before python will be a truly 21st century language. We should have never written code like this... ------------ Example 1: ------------ # lst = [] if lst: blah if not lst: blah Example 1 is not explicit enough. Too much guessing is required by the reader! ----------- Example 2 ----------- if lst.lengh > 0: blah if not lst.empty(): blah if not empty(lst): blah Example 2 is just explicit enough so that the reader knows *exactly* what is happening! We don't want to be redundantly explicit, however we sure as *hell* don't want to be implicit! Hmm, believe i read that somewhere once... import this! The point is NEVER use an integer in place of a boolean! And i am NOT blaming the OP here, no! I am blaming who ever came up with this idiotic "emulation of booleans" crap! And don't tell me... "Well C did it first we were just following by example"... because you just make yourself out to be even a bigger idiot! Here is another example of bad habits passed down from "on high". def is_foo(): if something: return 1 return 0 Why the HELL are you retuning integers in an obviously boolean function? Are you trying to win Pearl hacker of the year award? Please folks, always remember... NEVER emulate booleans, always use True/ False for boolean behaviors. def is_foo(): if something: return True return False *school-bell* From ricli85 at gmail.com Wed Feb 9 10:27:52 2011 From: ricli85 at gmail.com (Rickard Lindberg) Date: Wed, 9 Feb 2011 16:27:52 +0100 Subject: Unicode error in sax parser In-Reply-To: References: Message-ID: On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: > On Tue, Feb 8, 2011 at 7:57 AM, Rickard Lindberg wrote: >> Hi, >> >> Here is a bash script to reproduce my error: > > Including the error message and traceback is still helpful, for future > reference. > >> ? ?#!/bin/sh >> >> ? ?cat > ?.timeline < >> ? ?EOF >> >> ? ?python <> ? ?# encoding: utf-8 >> ? ?from xml.sax import parse >> ? ?from xml.sax.handler import ContentHandler >> ? ?parse(u"?.timeline", ContentHandler()) >> ? ?EOF >> >> If I instead do >> >> ? ?parse(u"?.timeline".encode("utf-8"), ContentHandler()) >> >> the script runs without errors. >> >> Is this a bug or expected behavior? > > Bug; open() figures out the filesystem encoding just fine. > Bug tracker to report the issue to: http://bugs.python.org/ > > Workaround: > parse(open(u"?.timeline", 'r'), ContentHandler()) > > Cheers, > Chris Bug reported at http://bugs.python.org/issue11159 -- Rickard Lindberg From brian.curtin at gmail.com Wed Feb 9 10:56:07 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Wed, 9 Feb 2011 09:56:07 -0600 Subject: PyCon 2011 news - going strong, sign up today! Message-ID: Hey python-list readers! PyCon 2011 looks like it may very well break every single record in the past - making it one of the biggest and best PyCons of all time. We've gone all out this year - including Extreme Talks, a Startup Row, amazing talks, tutorials, Poster sessions. Extreme talks: http://us.pycon.org/2011/speaker/extreme/ Startup Row: http://us.pycon.org/2011/blog/2011/01/19/announcing-startup-row-pycon-2011/ Also just announced - "Startup Stories": http://us.pycon.org/2011/blog/2011/02/07/pycon-2011-announcing-startup-stories/ If you haven't bought your PyCon tickets, it's time to do so. This year we're limited to 1500 attendees, and with a faster than average sales rate compared to previous years, you may not have the luxury of leaving registration until just before the conference -- places may sell out in advance! Check out http://us.pycon.org/2011/tickets/ for rates and details. Not sold on the conference? Not sure what it's all about? We are confident this year's conference will surpass anything that has gone before, and we think there's something for everyone. Looking for education? This year's tutorial selection features a range of topics and an all-star cast of presenters. From the cloud to the GUI, from beginner to advanced, we have it. Check out courses taught by book authors Wesley Chun and David Beazley, web framework master Jacob Kaplan-Moss, core developer and guru Raymond Hettinger, hacker extraordinaire Zed Shaw and many more: http://us.pycon.org/2011/schedule/tutorials/ -- and at flat fees that wouldn't buy you an hour of training by less-qualified instructors elsewhere! The conference talks are some of the best we've seen in years, coming from a record number of submissions. We've got talks on using Python for airplane tuning and massive telescopes. All of the major web frameworks will be discussed. Numerous databases are covered. PyPy, IronPython and Jython are in. We'll be talking about IDEs, testing, security, scalability, and documentation. Have a look: http://us.pycon.org/2011/schedule/lists/talks/ We've also got an amazing array of poster presentations - everything from Arduino hacking, Geospatial Python, Open Government and Microsoft Kinect hacking. Check out: http://us.pycon.org/2011/schedule/lists/posters/ Meanwhile we've got the awesome sprints (http://us.pycon.org/2011/sprints/ ), and open spaces (http://us.pycon.org/2011/openspaces/) everyone knows and loves. This is shaping up to be the best PyCon yet, and we think it's a great value, both cost-wise, and community-wise. We can guarantee that you'll come away with a head full of knowledge and amazing new friends and contacts. Get your tickets before they are gone: http://us.pycon.org/2011/tickets/ If you have any questions, comments or concerns - feel free to email Van Lindberg (van at python.org) or Jesse Noller (jnoller at python.org) or pycon-organizers (pycon-organizers at python.org). See you in Atlanta, Van Lindberg Jesse Noller The entire PyCon 2011 team http://us.pycon.org/2011 -------------- next part -------------- An HTML attachment was scrubbed... URL: From hanche at math.ntnu.no Wed Feb 9 11:07:33 2011 From: hanche at math.ntnu.no (Harald Hanche-Olsen) Date: Wed, 09 Feb 2011 17:07:33 +0100 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: [Icarus Sparry ] > The 'modern' way to do this is > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + Actually, I think it should be find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} + because grep behaves differently when given only one filename as opposed to several. -- * Harald Hanche-Olsen - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell From hanche at math.ntnu.no Wed Feb 9 11:10:19 2011 From: hanche at math.ntnu.no (Harald Hanche-Olsen) Date: Wed, 09 Feb 2011 17:10:19 +0100 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: [Icarus Sparry ] > The 'modern' way to do this is > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + Actually, I think it should be find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} + \; because grep behaves differently when given only one filename as opposed to several. -- * Harald Hanche-Olsen - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell From jeanmichel at sequans.com Wed Feb 9 11:19:01 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 Feb 2011 17:19:01 +0100 Subject: Remove whitespaces and line breaks in a XML file In-Reply-To: <9de1ca25-550d-4591-8255-c07d3e5e7b15@glegroupsg2000goo.googlegroups.com> References: <9de1ca25-550d-4591-8255-c07d3e5e7b15@glegroupsg2000goo.googlegroups.com> Message-ID: <4D52BE75.1050902@sequans.com> Josh English wrote: > I found the code posted at > > http://infix.se/2007/02/06/gentlemen-indent-your-xml > > quite helpful in turning my xml into human-readable structures. It works > best for XML-Data. > > Josh > It's done in one line with http://docs.python.org/library/xml.dom.minidom.html#xml.dom.minidom.Node.writexml JM From jeanmichel at sequans.com Wed Feb 9 11:28:55 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 09 Feb 2011 17:28:55 +0100 Subject: Python subprocesses experience mysterious delay in receiving stdin EOF In-Reply-To: References: <4D52037E.4000809@mrabarnett.plus.com> Message-ID: <4D52C0C7.4040004@sequans.com> Yang Zhang wrote: > On Wed, Feb 9, 2011 at 11:01 AM, MRAB wrote: > >> On 09/02/2011 01:59, Yang Zhang wrote: >> >>> I reduced a problem I was seeing in my application down into the >>> following test case. In this code, a parent process concurrently >>> spawns 2 (you can spawn more) subprocesses that read a big message >>> from the parent over stdin, sleep for 5 seconds, and write something >>> back. However, there's unexpected waiting happening somewhere, causing >>> the code to complete in 10 seconds instead of the expected 5. >>> >>> If you set `verbose=True`, you can see that the straggling subprocess >>> is receiving most of the messages, then waiting for the last chunk of >>> 3 chars---it's not detecting that the pipe has been closed. >>> Furthermore, if I simply don't do anything with the second process >>> (`doreturn=True`), the first process will *never* see the EOF. >>> >>> Any ideas what's happening? Further down is some example output. >>> Thanks in advance. >>> >>> from subprocess import * >>> from threading import * >>> from time import * >>> from traceback import * >>> import sys >>> verbose = False >>> doreturn = False >>> msg = (20*4096+3)*'a' >>> def elapsed(): return '%7.3f' % (time() - start) >>> if sys.argv[1:]: >>> start = float(sys.argv[2]) >>> if verbose: >>> for chunk in iter(lambda: sys.stdin.read(4096), ''): >>> print>> sys.stderr, '..', time(), sys.argv[1], 'read', >>> len(chunk) >>> else: >>> sys.stdin.read() >>> print>> sys.stderr, elapsed(), '..', sys.argv[1], 'done reading' >>> sleep(5) >>> print msg >>> else: >>> start = time() >>> def go(i): >>> print elapsed(), i, 'starting' >>> p = Popen(['python','stuckproc.py',str(i), str(start)], >>> stdin=PIPE, stdout=PIPE) >>> if doreturn and i == 1: return >>> print elapsed(), i, 'writing' >>> p.stdin.write(msg) >>> print elapsed(), i, 'closing' >>> p.stdin.close() >>> print elapsed(), i, 'reading' >>> p.stdout.read() >>> print elapsed(), i, 'done' >>> ts = [Thread(target=go, args=(i,)) for i in xrange(2)] >>> for t in ts: t.start() >>> for t in ts: t.join() >>> >>> Example output: >>> >>> 0.001 0 starting >>> 0.003 1 starting >>> 0.005 0 writing >>> 0.016 1 writing >>> 0.093 0 closing >>> 0.093 0 reading >>> 0.094 1 closing >>> 0.094 1 reading >>> 0.098 .. 1 done reading >>> 5.103 1 done >>> 5.108 .. 0 done reading >>> 10.113 0 done >>> >>> >> I changed 'python' to the path of python.exe and 'stuckproc.py' to its >> full path and tried it with Python 2.7 on Windows XP Pro. It worked as >> expected. >> > > Good point - I didn't specify that I'm seeing this on Linux (Ubuntu > 10.04's Python 2.6). > > python test.py 0.000 0 starting 0.026 0 writing 0.026 0 closing 0.026 0 reading 0.029 .. 0 done reading 0.030 1 starting 0.038 1 writing 0.058 1 closing 0.058 1 reading 0.061 .. 1 done reading 5.026 0 done 5.061 1 done on debian lenny (Python 2.5) JM From jenn.duerr at gmail.com Wed Feb 9 12:52:27 2011 From: jenn.duerr at gmail.com (noydb) Date: Wed, 9 Feb 2011 09:52:27 -0800 (PST) Subject: frequency of values in a field References: <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> <7x7hdarzol.fsf@ruckus.brouhaha.com> Message-ID: <60c7aa3d-ba64-43eb-9c32-d25c04b442d5@a5g2000vbs.googlegroups.com> > > The Decimal module is pretty slow but is conceptually probably the right > way to do this. ?With just 50k records it shouldn't be too bad. ?With > more records you might look for a faster way. > > ? ? from decimal import Decimal as D > ? ? from collections import defaultdict > > ? ? records = ['3.14159','2.71828','3.142857'] > > ? ? td = defaultdict(int) > ? ? for x in records: > ? ? ? ? td[D(x).quantize(D('0.01'))] += 1 > > ? ? print td > I played with this - it worked. Using Python 2.6 so counter no good. I require an output text file of sorted "key value" so I added (further code to write out to an actual textfile, not important here) >> for z in sorted(set(td)): >> print z, td[z] So it seems the idea is to add all the records in the particular field of interest into a list (record). How does one do this in pure Python? Normally in my work with gis/arcgis sw, I would do a search cursor on the DBF file and add each value in the particular field into a list (to populate records above). Something like: >> import arcgisscripting >> # Create the geoprocessor object >> gp = arcgisscripting.create() >> records_list = [] >> cur = gp.SearchCursor(dbfTable) >> row = cur.Next() >> while row: >> value = row.particular_field >> records_list.append(value) From Joshua.R.English at gmail.com Wed Feb 9 13:21:47 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 9 Feb 2011 10:21:47 -0800 (PST) Subject: frequency of values in a field In-Reply-To: <60c7aa3d-ba64-43eb-9c32-d25c04b442d5@a5g2000vbs.googlegroups.com> Message-ID: On Wednesday, February 9, 2011 9:52:27 AM UTC-8, noydb wrote: > > So it seems the idea is to add all the records in the particular field > of interest into a list (record). How does one do this in pure > Python? > Normally in my work with gis/arcgis sw, I would do a search cursor on > the DBF file and add each value in the particular field into a list > (to populate records above). Something like: > I'm not sure I understand what you mean by "pure Python." Decimal and collections are part of the standard library. If you mean "use no imports whatsoever," the code would look like: counts = {} for thing in long_list: key = make_key(thing) if key in counts: counts[key] += 1 else: counts[key] = 1 But using a few imports is cleaner and just as easy to troubleshoot. Josh From tkpmep at hotmail.com Wed Feb 9 13:22:38 2011 From: tkpmep at hotmail.com (tkpmep at hotmail.com) Date: Wed, 9 Feb 2011 10:22:38 -0800 (PST) Subject: Uploading files to an an FTP site through a proxy server which requires authentication Message-ID: <5e831e34-0c5c-49fe-8e4f-63108c9c5148@y3g2000vbh.googlegroups.com> I would like to upload files to a ftp site, but can't seem to get through our proxy server, which requires authentication. How can one do this in Python (I use 2.7, but am more than happy to use 3.2 rc2) Thanks in advance Thomas Philips From jenn.duerr at gmail.com Wed Feb 9 13:34:12 2011 From: jenn.duerr at gmail.com (noydb) Date: Wed, 9 Feb 2011 10:34:12 -0800 (PST) Subject: frequency of values in a field References: Message-ID: <53604a1e-6217-4490-961e-3734193b607f@w36g2000vbi.googlegroups.com> On Feb 9, 1:21?pm, Josh English wrote: > On Wednesday, February 9, 2011 9:52:27 AM UTC-8, noydb wrote: > > > So it seems the idea is to add all the records in the particular field > > of interest into a list (record). ?How does one do this in pure > > Python? > > Normally in my work with gis/arcgis sw, I would do a search cursor on > > the DBF file and add each value in the particular field into a list > > (to populate records above). ?Something like: > > I'm not sure I understand what you mean by "pure Python." Decimal and collections are part of the standard library. > > If you mean "use no imports whatsoever," the code would look like: > > counts = {} > for thing in long_list: > ? key = make_key(thing) > ? if key in counts: > ? ? counts[key] += 1 > ? else: > ? ? counts[key] = 1 > > But using a few imports is cleaner and just as easy to troubleshoot. > > Josh How do you add all the records in the particular field of interest into long_list? From rouslank at msn.com Wed Feb 9 13:54:41 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Wed, 09 Feb 2011 13:54:41 -0500 Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries Message-ID: I'm working on a program that automatically generates C++ code for a Python extension and I noticed a few limitations when using the weaklist and instance dictionaries (tp_weaklistoffset and tp_dictoffset). This is pertaining to the C API. I noticed that when using multiple inheritance, I need a common base class or I get an "instance lay-out conflict" error (my program already deals with the issue of having a varying layout), but the error also happens when the derived classes have these extra dictionaries and the common base doesn't. This doesn't seem like it should be a problem if the offsets for these variables are explicitly specified in the derived types. I want this program to be as flexible as possible, so could someone tell me what exactly are the rules when it comes to these dictionaries and inheritance. Also, I don't like the idea of having up to four different classes (one for every combination of those two variables) that do nothing except tell CPython that I know what I'm doing. Also is it possible to have a class that doesn't have these dictionaries derive from a class that does? I don't mind hackish solutions as long as they work reliably with multiple Python versions. From w_a_x_man at yahoo.com Wed Feb 9 13:55:45 2011 From: w_a_x_man at yahoo.com (William James) Date: 9 Feb 2011 18:55:45 GMT Subject: Land Of Lisp is out References: <94ec1613-f0b5-4a60-b164-c51c0b8be5ea@t20g2000yqa.googlegroups.com> <87bp6e9094.fsf@kuiper.lan.informatimago.com> Message-ID: Pascal J. Bourguignon wrote: > sthuebner at googlemail.com (Stefan H?bner) writes: > > >> Would it be right to say that the only Lisp still in common use is > the Elisp >> built into Emacs? > > > > Clojure (http://clojure.org) is a Lisp on the JVM. It's gaining > > more and more traction. > > There are actually 2 REAL Lisp on the JVM: > > - abcl http://common-lisp.net/project/armedbear/ and > > - CLforJava http://www.clforjava.org CL is not a real Lisp. It is an anti-Lisp, and those who use it are anti-Lispers. From old_road_farm at verizon.net Wed Feb 9 13:58:29 2011 From: old_road_farm at verizon.net (octopusgrabbus) Date: Wed, 9 Feb 2011 10:58:29 -0800 (PST) Subject: Programmatic Parsing of ps Message-ID: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> I have Python 2.6.6. I would like to get this output ps -ef | grep 'fglgo csm' into a list. What is the best way to do that? I've been reading the documentation, and am lost. Thank you. cmn From no.email at nospam.invalid Wed Feb 9 14:02:58 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 09 Feb 2011 11:02:58 -0800 Subject: wsgi, ajax, and multiple requests References: Message-ID: <7xwrl9f2u5.fsf@ruckus.brouhaha.com> "Frank Millman" writes: > So the question is, how can I achieve this with wsgi? If I detect that > I have received a request out of sequence, I can queue the request, > and send an empty response. I don't see how that can help, on the server side. Even if you send the responses in the right order, they might arrive at the client in the wrong order. So you have to do the reordering on the client. From no.email at nospam.invalid Wed Feb 9 14:08:24 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 09 Feb 2011 11:08:24 -0800 Subject: frequency of values in a field References: <53604a1e-6217-4490-961e-3734193b607f@w36g2000vbi.googlegroups.com> Message-ID: <7xsjvxf2l3.fsf@ruckus.brouhaha.com> noydb writes: >> counts = {} >> for thing in long_list: >> ? key = make_key(thing) >> ? if key in counts: >> ? ? counts[key] += 1 >> ? else: >> ? ? counts[key] = 1 counts = {} for thing i long_list: key = make_key(thing) counts[key] = 1 + counts.get(key, 0) > How do you add all the records in the particular field of interest > into long_list? I don't understand this question. Where are they coming from? From andreas.tawn at ubisoft.com Wed Feb 9 14:10:45 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Wed, 9 Feb 2011 20:10:45 +0100 Subject: frequency of values in a field In-Reply-To: <53604a1e-6217-4490-961e-3734193b607f@w36g2000vbi.googlegroups.com> References: <53604a1e-6217-4490-961e-3734193b607f@w36g2000vbi.googlegroups.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C0B9C9C281B@PDC-MAIL-CMS01.ubisoft.org> > How do you add all the records in the particular field of interest > into long_list? >From earlier in the thread you did... import arcgisscripting # Create the geoprocessor object gp = arcgisscripting.create() records_list = [] cur = gp.SearchCursor(dbfTable) row = cur.Next() while row: value = row.particular_field records_list.append(value) I'd rewrite that as... import arcgisscripting gp = arcgisscripting.create() cur = gp.SearchCursor(dbfTable) records_list = [row.particular_field for row in cur] # I've no experience of arcgis, # so I'm assuming that SearchCursor is an iterable of some sort Cheers, Drea From emile at fenx.com Wed Feb 9 14:15:39 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 09 Feb 2011 11:15:39 -0800 Subject: Programmatic Parsing of ps In-Reply-To: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> References: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> Message-ID: On 2/9/2011 10:58 AM octopusgrabbus said... > I have Python 2.6.6. I would like to get this output > > ps -ef | grep 'fglgo csm' > > into a list. What is the best way to do that? I've been reading the > documentation, and am lost. > > Thank you. > cmn commands.getoutput Emile From irmen at -NOSPAM-xs4all.nl Wed Feb 9 14:38:42 2011 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Wed, 09 Feb 2011 20:38:42 +0100 Subject: Socket connection between python and C In-Reply-To: References: Message-ID: <4d52ed42$0$81474$e4fe514c@news.xs4all.nl> On 09-02-11 01:54, Williamson, Ross X. (Guest) wrote: > Dear All, > > I'm trying to implement a server/client system where the server is written in python and the client has to be written in c/c++. I can happily send simple text through the socket. Ideally I would like make say a struct (using python struct library) - and then read that in using C. Is there a better way to package data on the server in python to send down a socket to a C client? XML? Pickle? > > Cheers, > > Ross For a binary protocol I recall once using the marshal module from Python to send simple data structures over a stream to a C program on the other end. The marshal protocol is simple and was parsed by the C code on the other end. Look in marshal.c in Python's source. Actually now I think of it, it was the other way around: there was a little bit of minimalistic code in a web server written in C, that encoded stuff in the marshal protocol, and it was the Python process that simply used the marshal module to get objects out of it. But I think it shouldn't be hard to make this 2-way if you make some restrictions on the data types you use. Binary protocols have their drawbacks though, and maybe it's best to go for Json instead for reasons mentioned already in the other replies. -irmen From pavlovevidence at gmail.com Wed Feb 9 14:42:59 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 9 Feb 2011 11:42:59 -0800 (PST) Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries References: Message-ID: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> On Feb 9, 10:54?am, Rouslan Korneychuk wrote: > I'm working on a program that automatically generates C++ code for a > Python extension and I noticed a few limitations when using the weaklist > and instance dictionaries (tp_weaklistoffset and tp_dictoffset). This is > pertaining to the C API. > > I noticed that when using multiple inheritance, I need a common base > class or I get an "instance lay-out conflict" error (my program already > deals with the issue of having a varying layout), but the error also > happens when the derived classes have these extra dictionaries and the > common base doesn't. This doesn't seem like it should be a problem if > the offsets for these variables are explicitly specified in the derived > types. No, it is a problem. It violates Liskov substitution principle. Let me see if I understand your situation. You have one base type with tp_dictoffset or tp_weakrefoffset set but no extra fields in the object structure, and another base type without tp_dictoffset or tp_weakrefoffset, but with extra fields, and you're trying to multiply- inherit from both? This is the only case I can think of where the layout conflict would be caused by a type setting tp_dictoffset. Even though this is a clear layout conflict, you think that if you set tp_dictoffset and tp_weakrefoffset appropiately in the derived type, it's ok if the dict and weakreflist appear in different locations in the subtype, right? Not in general. A bunch of stuff can go wrong. If any methods in the base type reference the object dict directly (rather than indirectly via tp_dictoffset), then the derived type will be broken when one of the base-type methods is called. (This alone is enough to rule out allowing it in general.) Even if you are careful to always use tp_dictoffset; a user might write a subtype in C that directly accesses it, not even stopping to consider that it might be used in MI. It's not even certain that a derived type won't use the base type's tp_dictoffset. The algorithm to detect layout conflicts would require a terrible increase in complexity: there's some of layouts that would "work" if you could ignore tp_dictoffset, and some that won't, and now you have a big mess trying to distinguish. Bottom line is, tp_dictoffset and tp_weakrefoffset should be treated as if they defined regular slots that affect layout, and it should be assumed that (like for all other slots) the offset does not change for subtypes. There's a few important situations where tp_dictoffset is a tiny bit more flexible than a regular slot, but that's rare. > I want this program to be as flexible as possible, so could > someone tell me what exactly are the rules when it comes to these > dictionaries and inheritance. Also, I don't like the idea of having up > to four different classes (one for every combination of those two > variables) that do nothing except tell CPython that I know what I'm doing. I don't think there's any reasonable way to subvert Python's behavior on layout. If your base types are abstract, you might consider not setting tp_dictoffset and tp_weakrefoffset in the base (even if it has methods that reference the dict)--just be sure to set it in the first class that's concrete. > Also is it possible to have a class that doesn't have these dictionaries > derive from a class that does? Nope. That would *really* violate Liskov substitution principle. Carl Banks From me+list/python at ixokai.io Wed Feb 9 14:45:44 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Wed, 09 Feb 2011 11:45:44 -0800 Subject: [python-list] - what do you think ? In-Reply-To: <4D525221.6030405@ixokai.io> References: <87vd0upyhx.fsf@benfinney.id.au> <4D525221.6030405@ixokai.io> Message-ID: <4D52EEE8.3030304@ixokai.io> On 2/9/11 12:36 AM, Stephen Hansen wrote: > .. yeah, no. Okay, I actually have to apologize for the tone of this message. It was late and I was a jerk. I could have just been helpful without including the jerk, but something about it set me off. So the helpful and the jerk got mixed in together. Sorry! -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From tassilo at member.fsf.org Wed Feb 9 14:48:44 2011 From: tassilo at member.fsf.org (Tassilo Horn) Date: Wed, 09 Feb 2011 20:48:44 +0100 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> Message-ID: <87lj1pdm5f.fsf@member.fsf.org> Xah Lee writes: >> You can rely on shell globbing, so that grep gets a list of all files in >> all subdirectories. ?For example, I can grep all header files of the >> linux kernel using >> >> ? % grep FOO /usr/src/linux/**/*.h > > say, i want to search in the dir > ~/web/xahlee_org/ > > but no more than 2 levels deep, and only files ending in ?.html?. This > is not a toy question. I actually need to do that. % grep ~/web/xahlee_org/*{,/*}.html FOO That'll grep files like ~/web/xahlee_org/bla.html as well as ~/web/xahlee_org/bla/bla.html, but not any deeper. >> However, on older systems or on windows, that may produce a too long >> command line. ?Alternatively, you can use the -R option to grep a >> directory recursively, and specify an include globbing pattern (or many, >> and/or one or many exclude patterns). >> >> ? % grep -R FOO --include='*.h' /usr/src/linux/ >> >> You can also use a combination of `find', `xargs' and `grep' (with some >> complications for allowing spaces in file names [-print0 to find]), or, >> when using zsh, you can use >> >> ? % zargs /usr/src/linux/**/*.h -- grep FOO >> >> which does all relevant quoting and stuff for you. > > problem with find xargs is that they spawn grep for each file, which > becomes too slow to be usable. I can see not speed difference in find | xargs grep or grep with glob... > To not use xargs but ?find ... -exec? instead is possible of course > but i always have problems with the syntax... Yeah, there are so many ways. ;-) >> There are many things you can also do with a plain shell script. ?I'm >> always amazed how good and concise you can do all sorts of file/text >> manipulation using `zsh' builtins. > > never really got into bash for shell scripting... sometimes tried but > the ratio power/syntax isn't tolerable. Knowing perl well pretty much > killed any possible incentive left. Yeah, perl is a swiss army knife, but I never got comfortable with it. > Also note, this shell script can't be replaced by elisp, because elisp > is not suitable when the file size is large. You could chunk the file and handle the parts separately, in order to not have everything in an emacs buffer and thus getting out of RAM. Bye, Tassilo From psilord at cs.wisc.edu Wed Feb 9 15:02:26 2011 From: psilord at cs.wisc.edu (Peter Keller) Date: Wed, 9 Feb 2011 20:02:26 +0000 (UTC) Subject: Land Of Lisp is out References: <94ec1613-f0b5-4a60-b164-c51c0b8be5ea@t20g2000yqa.googlegroups.com> <87bp6e9094.fsf@kuiper.lan.informatimago.com> Message-ID: In comp.lang.lisp William James wrote: > Pascal J. Bourguignon wrote: > >> sthuebner at googlemail.com (Stefan H?bner) writes: >> >> >> Would it be right to say that the only Lisp still in common use is >> the Elisp >> built into Emacs? >> > >> > Clojure (http://clojure.org) is a Lisp on the JVM. It's gaining >> > more and more traction. >> >> There are actually 2 REAL Lisp on the JVM: >> >> - abcl http://common-lisp.net/project/armedbear/ and >> >> - CLforJava http://www.clforjava.org > > CL is not a real Lisp. It is an anti-Lisp, and those who use it > are anti-Lispers. Did you find out you were the illegitimate child of your mom who once had a tryst with Common Lisp? It is the only explanation of your vehemence. I could see the cultural problem of being a half-breed in an Algol-68 world and how it can be the source of your disdain for CL. You often see it in times of war: Half Vietnamese, Half Japanese, Half Orc. No one side wants to accept the impropriety... Maybe this is why a staunch Ruby advocate hangs out in comp.lang.lisp. comp.lang.ruby rejected you worse. -pete From Joshua.R.English at gmail.com Wed Feb 9 15:08:56 2011 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 9 Feb 2011 12:08:56 -0800 (PST) Subject: frequency of values in a field In-Reply-To: <53604a1e-6217-4490-961e-3734193b607f@w36g2000vbi.googlegroups.com> Message-ID: <239c9dee-b8a3-486c-b359-2d2ac6725db5@glegroupsg2000goo.googlegroups.com> On Wednesday, February 9, 2011 10:34:12 AM UTC-8, noydb wrote: > > How do you add all the records in the particular field of interest > into long_list? Sorry to be unclear. In both cases I was tossing out pseudo-code, as I am not familiar with the arggisscripting module. long_list is a list with the records you want, or an iterator that goes through the records. The get_key function does whatever you need it to do to get the key by which you are counting. Andreas offers a nice pythonic solution in this thread. Josh From ethan at stoneleaf.us Wed Feb 9 15:28:48 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 09 Feb 2011 12:28:48 -0800 Subject: frequency of values in a field In-Reply-To: <60c7aa3d-ba64-43eb-9c32-d25c04b442d5@a5g2000vbs.googlegroups.com> References: <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> <7x7hdarzol.fsf@ruckus.brouhaha.com> <60c7aa3d-ba64-43eb-9c32-d25c04b442d5@a5g2000vbs.googlegroups.com> Message-ID: <4D52F900.6000801@stoneleaf.us> noydb wrote: > Paul Rubin wrote: >> The Decimal module is pretty slow but is conceptually probably the right >> way to do this. With just 50k records it shouldn't be too bad. With >> more records you might look for a faster way. >> >> from decimal import Decimal as D >> from collections import defaultdict >> >> records = ['3.14159','2.71828','3.142857'] >> >> td = defaultdict(int) >> for x in records: >> td[D(x).quantize(D('0.01'))] += 1 >> >> print td >> > > I played with this - it worked. Using Python 2.6 so counter no good. > > I require an output text file of sorted "key value" so I added > (further code to write out to an actual textfile, not important here) >>> for z in sorted(set(td)): >>> print z, td[z] > > So it seems the idea is to add all the records in the particular field > of interest into a list (record). How does one do this in pure > Python? > Normally in my work with gis/arcgis sw, I would do a search cursor on > the DBF file and add each value in the particular field into a list > (to populate records above). Something like: > > --> import arcgisscripting > --> # Create the geoprocessor object > --> gp = arcgisscripting.create() > --> records_list = [] > --> cur = gp.SearchCursor(dbfTable) > --> row = cur.Next() > --> while row: > --> value = row.particular_field > --> records_list.append(value) Are you trying to get away from arcgisscripting? There is a pure python dbf package on PyPI (I know, I put it there ;) that you can use to access the .dbf file in question (assuming it's a dBase III, IV, or FoxPro format). http://pypi.python.org/pypi/dbf/0.88.16 if you're interested. Using it, the code above could be: ----------------------------------------------------- import dbf from collections import defaultdict from decimal import Decimal table = dbf.Table('path/to/table/table_name') freq = defaultdict(int) for record in table: value = Decimal(record['field_of_interest']) key = value.quantize(Decimal('0.01')) freq[key] += 1 for z in sorted(freq): print z, freq[z] ----------------------------------------------------- Numeric/Float field types are returned as python floats*, so there may be slight discrepancies between the stored value and the returned value. Hope this helps. ~Ethan~ *Unless created with zero decimal places, in which case they are returned as python integers. From jenn.duerr at gmail.com Wed Feb 9 15:39:46 2011 From: jenn.duerr at gmail.com (noydb) Date: Wed, 9 Feb 2011 12:39:46 -0800 (PST) Subject: frequency of values in a field References: <239c9dee-b8a3-486c-b359-2d2ac6725db5@glegroupsg2000goo.googlegroups.com> Message-ID: <3f7a9842-877d-4c5e-a502-5e923be5ea32@o14g2000prb.googlegroups.com> On Feb 9, 3:08?pm, Josh English wrote: > On Wednesday, February 9, 2011 10:34:12 AM UTC-8, noydb wrote: > > > How do you add all the records in the particular field of interest > > into long_list? > > Sorry to be unclear. In both cases I was tossing out pseudo-code, as I am not familiar with the arggisscripting module. long_list is a list with the records you want, or an iterator that goes through the records. The get_key function does whatever you need it to do to get the key by which you are counting. > > ?Andreas offers a nice pythonic solution in this thread. > > Josh I apologize if I am not being clear. Bear with me, I am not a programmer by trade, just someone who has to delve into some python scripting occasionally (which I do enjoy!). No, I do not mean "use no imports whatsoever". Just don't want to use ArcGIS sw's module arcgisscritping -- fine to use when needed for GIS processing, but some of my scripts do not need it whatsoever, as I suspect in this case. I have a solution in place, which is fine, but I used arcgisscripting simply to put a search cursor on that field to get the values. This certainly can be done without arcgisscripting, which does add a bit of time to the running of the script. i just do not know how outside of using arcgisscripting search cursor. Just looking to learn how... So, in my scenario, taking into account suggested snippets above.... long_list would start out empty. The values to go into long_list are in one field in a dbf table that contains thousands of records. I need to create a text file containing all the frequencies of values (only to 2 decimal places... in the form "key count"). How do I get those values from the field into the empty list so that this code. Everything else is figured out (textfile, getting the frequencies (per suggestions above)) - just want to know how to add all the values in the column into the empty list? From stefan_ml at behnel.de Wed Feb 9 15:41:34 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 09 Feb 2011 21:41:34 +0100 Subject: Socket connection between python and C In-Reply-To: References: Message-ID: Williamson, Ross X. wrote: > I'm trying to implement a server/client system where the server is written in > python and the client has to be written in c/c++. Is this a strict requirement? Could you give us a hint why the client needs to be plain C/C++? Stefan From jenn.duerr at gmail.com Wed Feb 9 15:44:45 2011 From: jenn.duerr at gmail.com (noydb) Date: Wed, 9 Feb 2011 12:44:45 -0800 (PST) Subject: frequency of values in a field References: <2f463773-da89-4c50-bd4f-8f891e6038a7@d12g2000vbz.googlegroups.com> <7x7hdarzol.fsf@ruckus.brouhaha.com> <60c7aa3d-ba64-43eb-9c32-d25c04b442d5@a5g2000vbs.googlegroups.com> Message-ID: <279b0362-49d2-4c5a-929f-f579a9d29aa9@q2g2000pre.googlegroups.com> On Feb 9, 3:28?pm, Ethan Furman wrote: > noydb wrote: > > ?> Paul Rubin wrote: > > > > > > >> The Decimal module is pretty slow but is conceptually probably the right > >> way to do this. ?With just 50k records it shouldn't be too bad. ?With > >> more records you might look for a faster way. > > >> ? ? from decimal import Decimal as D > >> ? ? from collections import defaultdict > > >> ? ? records = ['3.14159','2.71828','3.142857'] > > >> ? ? td = defaultdict(int) > >> ? ? for x in records: > >> ? ? ? ? td[D(x).quantize(D('0.01'))] += 1 > > >> ? ? print td > > > I played with this - it worked. ?Using Python 2.6 so counter no good. > > > I require an output text file of sorted "key value" so I added > > (further code to write out to an actual textfile, not important here) > >>> for z in sorted(set(td)): > >>> ? ? print z, td[z] > > > So it seems the idea is to add all the records in the particular field > > of interest into a list (record). ?How does one do this in pure > > Python? > > Normally in my work with gis/arcgis sw, I would do a search cursor on > > the DBF file and add each value in the particular field into a list > > (to populate records above). ?Something like: > > > --> import arcgisscripting > > --> # Create the geoprocessor object > > --> gp = arcgisscripting.create() > > --> records_list = [] > > --> cur = gp.SearchCursor(dbfTable) > > --> row = cur.Next() > > --> while row: > > --> ? ?value = row.particular_field > > --> ? ?records_list.append(value) > > Are you trying to get away from arcgisscripting? ?There is a pure python > dbf package on PyPI (I know, I put it there ;) that you can use to > access the .dbf file in question (assuming it's a dBase III, IV, or > FoxPro format). > > http://pypi.python.org/pypi/dbf/0.88.16if you're interested. > > Using it, the code above could be: > > ----------------------------------------------------- > import dbf > from collections import defaultdict > from decimal import Decimal > > table = dbf.Table('path/to/table/table_name') > > freq = defaultdict(int) > for record in table: > ? ? ?value = Decimal(record['field_of_interest']) > ? ? ?key = value.quantize(Decimal('0.01')) > ? ? ?freq[key] += 1 > > for z in sorted(freq): > ? ? ?print z, freq[z] > > ----------------------------------------------------- > > Numeric/Float field types are returned as python floats*, so there may > be slight discrepancies between the stored value and the returned value. > > Hope this helps. > > ~Ethan~ > > *Unless created with zero decimal places, in which case they are > returned as python integers.- Hide quoted text - > > - Show quoted text - Oops, didn't see htis before I posted last. Thanks! I'll try this, looks good, makes sense. From rouslank at msn.com Wed Feb 9 16:14:59 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Wed, 09 Feb 2011 16:14:59 -0500 Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries In-Reply-To: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> References: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> Message-ID: On 02/09/2011 02:42 PM, Carl Banks wrote: > On Feb 9, 10:54 am, Rouslan Korneychuk wrote: >> I'm working on a program that automatically generates C++ code for a >> Python extension and I noticed a few limitations when using the weaklist >> and instance dictionaries (tp_weaklistoffset and tp_dictoffset). This is >> pertaining to the C API. >> >> I noticed that when using multiple inheritance, I need a common base >> class or I get an "instance lay-out conflict" error (my program already >> deals with the issue of having a varying layout), but the error also >> happens when the derived classes have these extra dictionaries and the >> common base doesn't. This doesn't seem like it should be a problem if >> the offsets for these variables are explicitly specified in the derived >> types. > > No, it is a problem. It violates Liskov substitution principle. > > Let me see if I understand your situation. You have one base type > with tp_dictoffset or tp_weakrefoffset set but no extra fields in the > object structure, and another base type without tp_dictoffset or > tp_weakrefoffset, but with extra fields, and you're trying to multiply- > inherit from both? This is the only case I can think of where the > layout conflict would be caused by a type setting tp_dictoffset. No, actually I have code that is roughly equivalent to the following pseudocode: class _internal_class(object): __slots__ = () class BaseA(_internal_class): __slots__ = (some_data,...,__weaklist__,__dict__) class BaseB(BaseA): __slots__ = (some_data,...,__weaklist__,__dict__) class BaseC(_internal_class): __slots__ = (some_other_data,...,__weaklist__,__dict__) class Derived(BaseB,BaseC): __slots__ = (combined_data,...,__weaklist__,__dict__) Before adding the weaklist and instance dicts, this all worked fine. _internal_class was necessary to prevent the "lay-out conflict" error. But when I added them to every class except _internal_class, I got the error. I tried adding the dicts to _internal_class and it worked again. (The classes are set up like this because the code is from my unit-test code.) > Even though this is a clear layout conflict, you think that if you set > tp_dictoffset and tp_weakrefoffset appropiately in the derived type, > it's ok if the dict and weakreflist appear in different locations in > the subtype, right? > > Not in general. A bunch of stuff can go wrong. If any methods in the > base type reference the object dict directly (rather than indirectly > via tp_dictoffset), then the derived type will be broken when one of > the base-type methods is called. (This alone is enough to rule out > allowing it in general.) Even if you are careful to always use > tp_dictoffset; a user might write a subtype in C that directly > accesses it, not even stopping to consider that it might be used in > MI. It's not even certain that a derived type won't use the base > type's tp_dictoffset. > > The algorithm to detect layout conflicts would require a terrible > increase in complexity: there's some of layouts that would "work" if > you could ignore tp_dictoffset, and some that won't, and now you have > a big mess trying to distinguish. > > Bottom line is, tp_dictoffset and tp_weakrefoffset should be treated > as if they defined regular slots that affect layout, and it should be > assumed that (like for all other slots) the offset does not change for > subtypes. There's a few important situations where tp_dictoffset is a > tiny bit more flexible than a regular slot, but that's rare. > > >> I want this program to be as flexible as possible, so could >> someone tell me what exactly are the rules when it comes to these >> dictionaries and inheritance. Also, I don't like the idea of having up >> to four different classes (one for every combination of those two >> variables) that do nothing except tell CPython that I know what I'm doing. > > I don't think there's any reasonable way to subvert Python's behavior > on layout. > > If your base types are abstract, you might consider not setting > tp_dictoffset and tp_weakrefoffset in the base (even if it has methods > that reference the dict)--just be sure to set it in the first class > that's concrete. > > >> Also is it possible to have a class that doesn't have these dictionaries >> derive from a class that does? > > Nope. That would *really* violate Liskov substitution principle. This is why the code is automatically generated and is not meant to be extended by hand. It already does more complicated things. Even without inheritance, the layout of the classes can vary. Each Python class is a wrapper for a C++ class. The C++ class is kept in the PyObject by copy, by default. But it can also be stored by a pointer that is deleted when the PyObject is gone. It can be stored as a reference to a member of another exposed C++ class, along with a PyObject pointer to that class. And it can also be stored as an unmanaged reference (this is intended for static objects). On top of that, anything that isn't used, is omitted, so that each class can be as small and efficient as possible. So I have already thrown internal consistency out the window. This all works by the way. You can check it out at https://github.com/Rouslan/PyExpose (although I haven't uploaded the code for supporting the weaklist and instance dictionaries yet). There may be a few edge cases where it fails when having very different requirements between inherited types, but I plan to write more test-cases and work everything out. From drsalists at gmail.com Wed Feb 9 16:34:55 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 9 Feb 2011 13:34:55 -0800 Subject: Programmatic Parsing of ps In-Reply-To: References: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> Message-ID: On Wed, Feb 9, 2011 at 11:15 AM, Emile van Sebille wrote: > On 2/9/2011 10:58 AM octopusgrabbus said... >> >> I have Python 2.6.6. I would like to get this output >> >> ps -ef | grep 'fglgo csm' >> >> into a list. What is the best way to do that? I've been reading the >> documentation, and am lost. >> >> Thank you. >> cmn > > commands.getoutput > > Emile Also, consider using "ps -eo pid,comm" (or similar) instead of ps -ef - it should be easier to parse that way. From jason.swails at gmail.com Wed Feb 9 16:42:13 2011 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 9 Feb 2011 16:42:13 -0500 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> Message-ID: You've gotten several good explanations, mainly saying that 0 -> False and not 0 -> True, which is why the while loop exits. You've also gotten advice about how to make your method more robust (i.e. force integer division). However, as surprising as this may be I'm actually with RR on this one (for a little) -- for code readability's sake, you should make your conditional more readable (i.e. don't depend on the fact that the iterations will take your test value down to 0 which conveniently in this case evaluates to False). This could encourage you in later cases to think that if this result eventually converged to a different number, say the multiplicative identity instead, that the same approach will work (when instead it'll dump you into an infinite loop). You've also gotten the suggestion of typecasting to a string and then looking at the number of characters in the string. This works fine for integers and positive numbers, but not so well for negatives and floats, since both the decimal and negative sign will be counted. You could typecast to a string then strip out '-' and '.' and then count the characters. i.e. def num_digits(n): return len(str(n).replace('-','').replace('.','')) Or typecast to an int if you want to neglect decimals before converting to a string, etc. Or use recursion! >>> def num_digits(n): ... if n == 0: ... return 0 ... else: ... return num_digits(n//10) + 1 ... >>> num_digits(1) 1 >>> num_digits(0) 0 >>> num_digits(10) 2 >>> num_digits(1131341) 7 Why the HELL are you retuning integers in an obviously boolean > function? Are you trying to win Pearl hacker of the year award? Please > folks, always remember... NEVER emulate booleans, always use True/ > False for boolean behaviors. > > def is_foo(): > if something: > return True > return False > NEVER? >>> True = 0 >>> True == False True >>> bool(True) False (I know this is fixed in py3) I think 0 -> False, 1-> True is perfectly reasonable and is fairly common in many languages (only Fortran in the languages I use doesn't use this construct). Not a serious issue in any case. --Jason > *school-bell* > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Paul.J.Symonds at gmail.com Wed Feb 9 16:50:00 2011 From: Paul.J.Symonds at gmail.com (Paul Symonds) Date: Wed, 9 Feb 2011 21:50:00 +0000 Subject: OO Python Message-ID: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Are there any good resources to learn OO Python from? From kb1pkl at aim.com Wed Feb 9 16:55:12 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Wed, 09 Feb 2011 16:55:12 -0500 Subject: OO Python In-Reply-To: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> References: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Message-ID: <4D530D40.1050109@aim.com> On 02/09/2011 04:50 PM, Paul Symonds wrote: > Are there any good resources to learn OO Python from? > To my knowledge, all Python is OO. What specifically about OOP do you want to know? http://www.alan-g.me.uk/tutor/tutclass.htm I've always liked Alan's site. Come over to the Tutor list if you need basic help, tutor at python.org. From pavlovevidence at gmail.com Wed Feb 9 16:58:12 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 9 Feb 2011 13:58:12 -0800 (PST) Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries References: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> Message-ID: On Feb 9, 1:14?pm, Rouslan Korneychuk wrote: > On 02/09/2011 02:42 PM, Carl Banks wrote: > > This is the only case I can think of where the > > layout conflict would be caused by a type setting tp_dictoffset. > > No, actually I have code that is roughly equivalent to the following > pseudocode: > > class _internal_class(object): > ? ? ?__slots__ = () > > class BaseA(_internal_class): > ? ? ?__slots__ = (some_data,...,__weaklist__,__dict__) > > class BaseB(BaseA): > ? ? ?__slots__ = (some_data,...,__weaklist__,__dict__) > > class BaseC(_internal_class): > ? ? ?__slots__ = (some_other_data,...,__weaklist__,__dict__) > > class Derived(BaseB,BaseC): > ? ? ?__slots__ = (combined_data,...,__weaklist__,__dict__) Ah, ok. So BaseA sticks weaklist and dict into a certain layout location. BaseB gets the same location because it has the same layout. BaseC sticks weaklist and dict into a different location. Derived then can't reconcile it because dict and weakref are in different locations. Again, for the reasons I mentioned the layouts conflict even if you set tp_weakreflist and tp_dictoffset. > Before adding the weaklist and instance dicts, this all worked fine. > _internal_class was necessary to prevent the "lay-out conflict" error. That actually seems like an error to me. It should signal a conflict if bases have different layout sizes from their own base, and one isn't a base of the other, which wouldn't be the case here. "some_data" a proper subset of "some_other_data", right? (If it isn't you have worse problems than dict and weakreflist.) A more natural way to handle this situation would be to place common slots in the internal_class. But we'll just accept it for now. > But when I added them to every class except _internal_class, I got the > error. I tried adding the dicts to _internal_class and it worked again. > (The classes are set up like this because the code is from my unit-test > code.) Don't set tp_dictoffset and tp_weakrefoffset in any of the bases. Set them only in Derived. If you need to instantiate a Base, make a trivial dervied class for it. Carl Banks From pavlovevidence at gmail.com Wed Feb 9 17:02:26 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 9 Feb 2011 14:02:26 -0800 (PST) Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries References: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> Message-ID: <9e3b4a69-ea1a-4d55-95ec-5175fbbfa2b3@w7g2000pre.googlegroups.com> On Feb 9, 1:14?pm, Rouslan Korneychuk wrote: > Each Python class is a wrapper for a C++ class. Also, if you want my opinion (you probably don't after you've already gone to so much trouble, but here it is anyway): It's not worth it to mimic the C++ type hierarchy in Python. Just wrap each C++ class, regardless of its ancestry, in a Python class with only object as base. Carl Banks From python at mrabarnett.plus.com Wed Feb 9 17:34:21 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 09 Feb 2011 22:34:21 +0000 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> Message-ID: <4D53166D.6050103@mrabarnett.plus.com> On 09/02/2011 21:42, Jason Swails wrote: > You've gotten several good explanations, mainly saying that 0 -> False > and not 0 -> True, which is why the while loop exits. You've also > gotten advice about how to make your method more robust (i.e. force > integer division). > > However, as surprising as this may be I'm actually with RR on this one > (for a little) -- for code readability's sake, you should make your > conditional more readable (i.e. don't depend on the fact that the > iterations will take your test value down to 0 which conveniently in > this case evaluates to False). This could encourage you in later cases > to think that if this result eventually converged to a different number, > say the multiplicative identity instead, that the same approach will > work (when instead it'll dump you into an infinite loop). > > You've also gotten the suggestion of typecasting to a string and then > looking at the number of characters in the string. This works fine for > integers and positive numbers, but not so well for negatives and floats, > since both the decimal and negative sign will be counted. You could > typecast to a string then strip out '-' and '.' and then count the > characters. i.e. > > def num_digits(n): > return len(str(n).replace('-','').replace('.','')) > Or: def num_digits(n): return len(str(abs(n)).replace('.','')) > Or typecast to an int if you want to neglect decimals before converting > to a string, etc. > [snip] Python doesn't have typecasting. :-) From skunkworks at rikishi42.net Wed Feb 9 17:54:13 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Wed, 9 Feb 2011 23:54:13 +0100 Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> Message-ID: On 2011-02-09, Michael Hrivnak wrote: > Your function only works if n is an integer. Example: > >>>> num_digits(234) > 3 >>>> num_digits(23.4) > 325 > > When doing integer division, python will throw away the remainder and > return an int. Using your example of n==44, 44/10 == 4 and 4/10 == 0 > > Before each iteration of the while loop, the given expression (in this > case just n) is evaluated as a boolean. Your function would act the > same if it looked like this: > > def num_digits(n): > count = 0 > while bool(n): > count = count + 1 > n = n / 10 > return count > > 0 of course evaluates to False as a boolean, which is why the while loop stops. > > Just for kicks, this function would work about as well: > > def num_digits(n): > return len(str(n)) What about this one: import math def num_digits(n): return int(math.ceil(math.log(n,10))) -- When in doubt, use brute force. -- Ken Thompson From skunkworks at rikishi42.net Wed Feb 9 18:00:48 2011 From: skunkworks at rikishi42.net (Rikishi42) Date: Thu, 10 Feb 2011 00:00:48 +0100 Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> Message-ID: <0uib28-6aq.ln1@murmur.very.softly> On 2011-02-09, rantingrick wrote: > On Feb 9, 1:08?am, Paul Rudin wrote: >> Nanderson writes: >> > loop would be infinite. I get what is happening in the function, and I >> > understand why this would work, but for some reason it's confusing me >> > as to how it is exiting the loop after a certain number of times. Help >> > is appreciated, thanks. >> >> It works because 0 tests false and because integer division yields >> integers... eventually you'll get something like 1/10 giving 0. > > It works because of a design flaw in the language! Specifically i am > referring to treating the integer 0 as False and any other integers as > True. There is also the empty vs non empty containers that work this > way besides numeric types. I would have defined the flaw to be use of '/' for the integer division. Using 0 as false and any other value as true is hardly unique to python. Lots of languages have been doing this long before Python even existed. -- When in doubt, use brute force. -- Ken Thompson From rouslank at msn.com Wed Feb 9 18:11:26 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Wed, 09 Feb 2011 18:11:26 -0500 Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries In-Reply-To: References: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> Message-ID: On 02/09/2011 04:58 PM, Carl Banks wrote: > On Feb 9, 1:14 pm, Rouslan Korneychuk wrote: >> On 02/09/2011 02:42 PM, Carl Banks wrote: >>> This is the only case I can think of where the >>> layout conflict would be caused by a type setting tp_dictoffset. >> >> No, actually I have code that is roughly equivalent to the following >> pseudocode: >> >> class _internal_class(object): >> __slots__ = () >> >> class BaseA(_internal_class): >> __slots__ = (some_data,...,__weaklist__,__dict__) >> >> class BaseB(BaseA): >> __slots__ = (some_data,...,__weaklist__,__dict__) >> >> class BaseC(_internal_class): >> __slots__ = (some_other_data,...,__weaklist__,__dict__) >> >> class Derived(BaseB,BaseC): >> __slots__ = (combined_data,...,__weaklist__,__dict__) > > Ah, ok. So BaseA sticks weaklist and dict into a certain layout > location. BaseB gets the same location because it has the same > layout. > BaseC sticks weaklist and dict into a different location. Derived > then can't reconcile it because dict and weakref are in different > locations. That doesn't explain why changing _internal_class to: class _internal_class(object): __slots__ = (__weaklist__,__dict__) makes it work. Also, why does Derived need to reconcile anything if I'm telling it where the dictionaries are in the new class? Doesn't CPython calculate where, for example, weaklist is with what is essentially: obj_instance + obj_instance->ob_type->tp_weaklistoffset (at least when tp_weaklistoffset is non-negative)? If so, then it wouldn't matter what the base classes look like. > "some_data" a proper subset of "some_other_data", right? (If it isn't > you have worse problems than dict and weakreflist.) Not at all. The point of this, is to allow C++ multiple inheritance to be mapped to Python multiple inheritance. I solve this issue as follows: All attributes of base classes of multiply-inheriting classes are turned into properties. Any time the wrapped C++ object needs to be accessed, the PyObject self variable's type is compared to every derived type that also inherits from another type. If it matches a derived type, a reinterpret_cast is performed on the C++ object to the derived C++ type, and then an implicit cast is performed to the intended type, which allows the proper pointer fix-up to happen. Here is the actual function that does that for BaseA: BaseA &get_base_BaseA(PyObject *x,bool safe = true) { if(reinterpret_cast(static_cast(reinterpret_cast(1))) != 1 && PyObject_IsInstance(x,reinterpret_cast(get_obj_DerivedType()))) return cast_base_Derived(x); if(UNLIKELY(safe && !PyObject_IsInstance(x,reinterpret_cast(get_obj_BaseAType())))) { PyErr_SetString(PyExc_TypeError,"object is not an instance of BaseA"); throw py_error_set(); } assert(PyObject_IsInstance(x,reinterpret_cast(get_obj_BaseAType()))); return cast_base_BaseA(x); } (cast_base_X checks how the C++ object is stored and retrieves a reference to it. The "reinterpret_cast(static_cast(reinterpret_cast(1))) != 1" part is an optimization trick. It checks to see if a pointer fix-up is even necessary. If not, that 'if' statement will be subject to dead code removal.) Of course, if this was hand-written code, such a method would be very brittle and would be a nightmare to maintain, but it's generated by a Python program and only needs to be correct. > Don't set tp_dictoffset and tp_weakrefoffset in any of the bases. Set > them only in Derived. If you need to instantiate a Base, make a > trivial dervied class for it. That would mean calling isinstance(derived_instance,BaseType) would return false. In any case, I'm writing a general-purpose tool and not trying to solve a specific problem. If I can't do what I'm trying to do here, I can just make the program not allow multiply-inheriting classes to derive (directly or indirectly) from classes that have a different combination of weaklist and dict (having both will be the default anyway, so this is a special case). From rouslank at msn.com Wed Feb 9 18:19:34 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Wed, 09 Feb 2011 18:19:34 -0500 Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries In-Reply-To: <9e3b4a69-ea1a-4d55-95ec-5175fbbfa2b3@w7g2000pre.googlegroups.com> References: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> <9e3b4a69-ea1a-4d55-95ec-5175fbbfa2b3@w7g2000pre.googlegroups.com> Message-ID: On 02/09/2011 05:02 PM, Carl Banks wrote: > On Feb 9, 1:14 pm, Rouslan Korneychuk wrote: >> Each Python class is a wrapper for a C++ class. > > Also, if you want my opinion (you probably don't after you've already > gone to so much trouble, but here it is anyway): No, your opinion is quite welcome. > It's not worth it to mimic the C++ type hierarchy in Python. Just > wrap each C++ class, regardless of its ancestry, in a Python class > with only object as base. I kind-of already did. The issue only comes up when multiply-inheriting from types that have a different combination of the weaklist and instance dictionaries. I don't have to support this particular feature. As for the worth, this is something I'm working on in my spare time as a hobby and I enjoy a good challenge. From rantingrick at gmail.com Wed Feb 9 18:47:41 2011 From: rantingrick at gmail.com (rantingrick) Date: Wed, 9 Feb 2011 15:47:41 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <0uib28-6aq.ln1@murmur.very.softly> Message-ID: <500338d0-e704-4a1d-89eb-3f823d9e68ac@u14g2000vbg.googlegroups.com> On Feb 9, 5:00?pm, Rikishi42 wrote: [...] > Using 0 as false and any other value as true is hardly unique to python. Lots > of languages have been doing this long before Python even existed. Well, the only way to reply is to paraphrase an anecdotes my mother would tell me often as a young lad... Mother: "Just because other language developers choose to jump off the cliffs of implicit-ey should we jump also?" Son: i guess not Mother: Now brush your teeth and go to bed. From steve+comp.lang.python at pearwood.info Wed Feb 9 19:22:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Feb 2011 00:22:37 GMT Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <0uib28-6aq.ln1@murmur.very.softly> Message-ID: <4d532fcd$0$29990$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Feb 2011 00:00:48 +0100, Rikishi42 wrote: > I would have defined the flaw to be use of '/' for the integer division. Well, it was a long time ago, when it seemed like a good idea. Now, Python has // for integer division. -- Steven From ben+python at benfinney.id.au Wed Feb 9 19:24:47 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 10 Feb 2011 11:24:47 +1100 Subject: OO Python References: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Message-ID: <874o8cpwhc.fsf@benfinney.id.au> Paul Symonds writes: > Are there any good resources to learn OO Python from? The first resource to use is the Python tutorial . Work through the whole thing: read the text and run the examples yourself, then experiment until you understand the points before moving to the next part. -- \ ?Every man would like to be God, if it were possible; some few | `\ find it difficult to admit the impossibility.? ?Bertrand | _o__) Russell, _Power: A New Social Analysis_, 1938 | Ben Finney From anikom15 at gmail.com Wed Feb 9 19:34:46 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Wed, 09 Feb 2011 16:34:46 -0800 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> Message-ID: <1297298086.2481.5.camel@localhost.localdomain> On Wed, 2011-02-09 at 06:51 -0800, rantingrick wrote: > On Feb 9, 1:08 am, Paul Rudin wrote: > > Nanderson writes: > > > loop would be infinite. I get what is happening in the function, and I > > > understand why this would work, but for some reason it's confusing me > > > as to how it is exiting the loop after a certain number of times. Help > > > is appreciated, thanks. > > > > It works because 0 tests false and because integer division yields > > integers... eventually you'll get something like 1/10 giving 0. > > It works because of a design flaw in the language! Specifically i am > referring to treating the integer 0 as False and any other integers as > True. There is also the empty vs non empty containers that work this > way besides numeric types. > > ---------------------------------- > Python 3.1.1 Interactive Session > ---------------------------------- > >>> bool(0) > False > >>> bool(1) > True > >>> bool(-1) > True > >>> bool(-1.0) > True > >>> bool(1.0) > True > >>> bool(0.0) > False > >>> bool([]) > False > >>> bool([1]) > True > > Sure it *seems* like a "bright" idea at first however later you find > out this sort of laziness just induces more subtle bugs in code. > Python3000 fixed a lot of warts in Python2.x HOWEVER, python3000 did > not go near far enough! We need more radical changes (and when i say > radical i mean removing poorly thought out design patterns like this > "boolean emulation"!) to the language before python will be a truly > 21st century language. > > We should have never written code like this... > > ------------ > Example 1: > ------------ > # lst = [] > > if lst: > blah > if not lst: > blah > > Example 1 is not explicit enough. Too much guessing is required by the > reader! > > ----------- > Example 2 > ----------- > if lst.lengh > 0: > blah > if not lst.empty(): > blah > if not empty(lst): > blah > > Example 2 is just explicit enough so that the reader knows *exactly* > what is happening! We don't want to be redundantly explicit, however > we sure as *hell* don't want to be implicit! Hmm, believe i read that > somewhere once... import this! > > The point is NEVER use an integer in place of a boolean! And i am NOT > blaming the OP here, no! I am blaming who ever came up with this > idiotic "emulation of booleans" crap! And don't tell me... "Well C did > it first we were just following by example"... because you just make > yourself out to be even a bigger idiot! > > Here is another example of bad habits passed down from "on high". > > def is_foo(): > if something: > return 1 > return 0 > > Why the HELL are you retuning integers in an obviously boolean > function? Are you trying to win Pearl hacker of the year award? Please > folks, always remember... NEVER emulate booleans, always use True/ > False for boolean behaviors. > > def is_foo(): > if something: > return True > return False > > *school-bell* Can you explain what you would define True and False as? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler at tysdomain.com Wed Feb 9 19:41:48 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 09 Feb 2011 17:41:48 -0700 Subject: Easy function, please help. In-Reply-To: <1297298086.2481.5.camel@localhost.localdomain> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <1297298086.2481.5.camel@localhost.localdomain> Message-ID: <4D53344C.1090904@tysdomain.com> Uh oh, I think we found RR's evil twin: another python to the modern day visionary. >Example 1 is not explicit enough. Too much guessing is required by the >reader! if list is empty, bla. if not, bla. it's not all that hard, and there's no guessing that needs to take place, honest. From wuwei23 at gmail.com Wed Feb 9 19:49:49 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 9 Feb 2011 16:49:49 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <0uib28-6aq.ln1@murmur.very.softly> <500338d0-e704-4a1d-89eb-3f823d9e68ac@u14g2000vbg.googlegroups.com> Message-ID: <563e429d-8663-4b9b-9b61-53d14499159d@o7g2000prn.googlegroups.com> rantingrick wrote: > Well, the only way to reply is to paraphrase an anecdotes my mother > would tell me often as a young lad... > > Mother: "Just because other language developers choose to jump off the > cliffs of implicit-ey should we jump also?" You think of yourself as a _language developer_? Oh that's classic. From simula67 at comcast.net Wed Feb 9 20:00:27 2011 From: simula67 at comcast.net (Eric Stechmann) Date: Wed, 9 Feb 2011 17:00:27 -0800 Subject: EPD 7.0 released In-Reply-To: References: Message-ID: <702586D5-9838-4166-A706-D07B77F38A65@comcast.net> Hi, son. Don't know if this would be of any interest to you. Well, I suppose it does provide some interesting. I hope your physical get-together will help out. Love you, David. Dad On Feb 9, 2011, at 8:13 AM, Ilan Schnell wrote: > Hello, > > I am pleased to announce that EPD (Enthought Python Distribution) > version 7.0 has been released. This major release updates to > Python 2.7, Intel Math Kernel Library 10.3.1, numpy 1.5.1, in > addition to updates to many of the other packages included. > Please find the complete list of additions, updates and bug fixes > in the change log: > > http://www.enthought.com/EPDChangelog.html > > To find more information about EPD, as well as download a 30 day > free trial, visit this page: > > http://www.enthought.com/products/epd.php > > > About EPD > --------- > The Enthought Python Distribution (EPD) is a "kitchen-sink-included" > distribution of the Python Programming Language, including over 90 > additional tools and libraries. The EPD bundle includes NumPy, SciPy, > IPython, 2D and 3D visualization, and many other tools. > > http://www.enthought.com/products/epdlibraries.php > > It is currently available as a single-click installer for Windows XP, > Vista and 7, MacOS (10.5 and 10.6), RedHat 3, 4 and 5, as well as > Solaris 10 (x86 and x86_64/amd64 on all platforms). > > All versions of EPD (32 and 64-bit) are free for academic use. An > annual subscription including installation support is available for > individual and commercial use. Additional support options, including > customization, bug fixes and training classes are also available: > > http://www.enthought.com/products/support_level_table.php > > > - Ilan > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ From ethan at stoneleaf.us Wed Feb 9 20:16:06 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 09 Feb 2011 17:16:06 -0800 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> Message-ID: <4D533C56.8030804@stoneleaf.us> Jason Swails wrote: > However, as surprising as this may be I'm actually with RR on this one > (for a little) -- for code readability's sake, you should make your > conditional more readable (i.e. don't depend on the fact that the > iterations will take your test value down to 0 which conveniently in > this case evaluates to False). while n: is plenty readable. n is either something or nothing, and something evaluates to True, nothing to False. > This could encourage you in later cases > to think that if this result eventually converged to a different number, > say the multiplicative identity instead, that the same approach will > work [...] See above comment -- something or nothing, not mathematical identities. > def num_digits(n): > return len(str(n).replace('-','').replace('.','')) > > Or typecast to an int if you want to neglect decimals before converting > to a string, etc. > > Or use recursion! > > >>> def num_digits(n): > ... if n == 0: > ... return 0 > ... else: > ... return num_digits(n//10) + 1 > ... > >>> num_digits(1) > 1 > >>> num_digits(0) > 0 0 is still one digit. ;) ~Ethan~ From pavlovevidence at gmail.com Wed Feb 9 20:40:47 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 9 Feb 2011 17:40:47 -0800 (PST) Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries References: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> Message-ID: On Feb 9, 3:11?pm, Rouslan Korneychuk wrote: > On 02/09/2011 04:58 PM, Carl Banks wrote: > > On Feb 9, 1:14 pm, Rouslan Korneychuk ?wrote: > >> On 02/09/2011 02:42 PM, Carl Banks wrote: > >>> This is the only case I can think of where the > >>> layout conflict would be caused by a type setting tp_dictoffset. > > >> No, actually I have code that is roughly equivalent to the following > >> pseudocode: > > >> class _internal_class(object): > >> ? ? ? __slots__ = () > > >> class BaseA(_internal_class): > >> ? ? ? __slots__ = (some_data,...,__weaklist__,__dict__) > > >> class BaseB(BaseA): > >> ? ? ? __slots__ = (some_data,...,__weaklist__,__dict__) > > >> class BaseC(_internal_class): > >> ? ? ? __slots__ = (some_other_data,...,__weaklist__,__dict__) > > >> class Derived(BaseB,BaseC): > >> ? ? ? __slots__ = (combined_data,...,__weaklist__,__dict__) > > > Ah, ok. ?So BaseA sticks weaklist and dict into a certain layout > > location. ?BaseB gets the same location because it has the same > > layout. > > BaseC sticks weaklist and dict into a different location. ?Derived > > then can't reconcile it because dict and weakref are in different > > locations. > > That doesn't explain why changing _internal_class to: > ? ? ?class _internal_class(object): > ? ? ? ? ?__slots__ = (__weaklist__,__dict__) > makes it work. Yes it does. When weaklist and dict are slots in the base class, then all the derived classes inherit those slots. So tp_dictoffset doesn't end up with one value in BaseB and a different value in BaseC. For the layouts to be compatible the dicts have to be in the same location. > Also, why does Derived need to reconcile anything if I'm > telling it where the dictionaries are in the new class? Doesn't CPython > calculate where, for example, weaklist is with what is essentially: > obj_instance + obj_instance->ob_type->tp_weaklistoffset > (at least when tp_weaklistoffset is non-negative)? If so, then it > wouldn't matter what the base classes look like. I explained why in my last post; there's a bunch of reasons. Generally you can't assume someone's going to go through the type structure to find the object's dict, nor can you expect inherited methods to always use the derived class's type structure (some methods might use their own type's tp_dictoffset or tp_weakreflist, which would be wrong if called from a superclass that changes those values). Even if you are careful to avoid such usage, the Python interpreter can't be sure. So it has to check for layout conflicts, and these checks would become very complex if it allowed dict and weakreflist to appear in different locations in the layout (it's have to check a lot more). > > "some_data" a proper subset of "some_other_data", right? ?(If it isn't > > you have worse problems than dict and weakreflist.) > > Not at all. The point of this, is to allow C++ multiple inheritance to > be mapped to Python multiple inheritance. I would say you do. Python's type system specifies that a derived type's layout is a superset of its base types' layout. You seem to have found a way to derive a type without a common layout, perhaps by exploiting a bug, and you claim to be able to keep data access straight. But Python types are not intended to work that way, and you are asking for trouble if you try to do it. I guess there's also no point in arguing that tp_dictoffset and tp_weakreflist need to have the same value for base and derived types, since you're rejecting the premise that layouts need to be compatible. Therefore, I'll only point out that the layout checking code is based on this premise, so that's why you're running afoul of it. [snip complicated variable access code] > > Don't set tp_dictoffset and tp_weakrefoffset in any of the bases. ?Set > > them only in Derived. ?If you need to instantiate a Base, make a > > trivial dervied class for it. > > That would mean calling isinstance(derived_instance,BaseType) would > return false. You claimed in another post you weren't trying to mimic the C++ type hierarchy in Python, but this line suggests you are. My suggestion was that you shouldn't; just don't create a type hierarchy at all in Python. Even more so if you're using Python 3, where isinstance() is customizable. Carl Banks From yanghatespam at gmail.com Wed Feb 9 21:37:52 2011 From: yanghatespam at gmail.com (Yang Zhang) Date: Thu, 10 Feb 2011 10:37:52 +0800 Subject: Python subprocesses experience mysterious delay in receiving stdin EOF In-Reply-To: <4D52C0C7.4040004@sequans.com> References: <4D52037E.4000809@mrabarnett.plus.com> <4D52C0C7.4040004@sequans.com> Message-ID: On Thu, Feb 10, 2011 at 12:28 AM, Jean-Michel Pichavant wrote: > Yang Zhang wrote: >> >> On Wed, Feb 9, 2011 at 11:01 AM, MRAB wrote: >> >>> >>> On 09/02/2011 01:59, Yang Zhang wrote: >>> >>>> >>>> I reduced a problem I was seeing in my application down into the >>>> following test case. In this code, a parent process concurrently >>>> spawns 2 (you can spawn more) subprocesses that read a big message >>>> from the parent over stdin, sleep for 5 seconds, and write something >>>> back. However, there's unexpected waiting happening somewhere, causing >>>> the code to complete in 10 seconds instead of the expected 5. >>>> >>>> If you set `verbose=True`, you can see that the straggling subprocess >>>> is receiving most of the messages, then waiting for the last chunk of >>>> 3 chars---it's not detecting that the pipe has been closed. >>>> Furthermore, if I simply don't do anything with the second process >>>> (`doreturn=True`), the first process will *never* see the EOF. >>>> >>>> Any ideas what's happening? Further down is some example output. >>>> Thanks in advance. >>>> >>>> ? ?from subprocess import * >>>> ? ?from threading import * >>>> ? ?from time import * >>>> ? ?from traceback import * >>>> ? ?import sys >>>> ? ?verbose = False >>>> ? ?doreturn = False >>>> ? ?msg = (20*4096+3)*'a' >>>> ? ?def elapsed(): return '%7.3f' % (time() - start) >>>> ? ?if sys.argv[1:]: >>>> ? ? ?start = float(sys.argv[2]) >>>> ? ? ?if verbose: >>>> ? ? ? ?for chunk in iter(lambda: sys.stdin.read(4096), ''): >>>> ? ? ? ? ?print>> ?sys.stderr, '..', time(), sys.argv[1], 'read', >>>> len(chunk) >>>> ? ? ?else: >>>> ? ? ? ?sys.stdin.read() >>>> ? ? ?print>> ?sys.stderr, elapsed(), '..', sys.argv[1], 'done reading' >>>> ? ? ?sleep(5) >>>> ? ? ?print msg >>>> ? ?else: >>>> ? ? ?start = time() >>>> ? ? ?def go(i): >>>> ? ? ? ?print elapsed(), i, 'starting' >>>> ? ? ? ?p = Popen(['python','stuckproc.py',str(i), str(start)], >>>> stdin=PIPE, stdout=PIPE) >>>> ? ? ? ?if doreturn and i == 1: return >>>> ? ? ? ?print elapsed(), i, 'writing' >>>> ? ? ? ?p.stdin.write(msg) >>>> ? ? ? ?print elapsed(), i, 'closing' >>>> ? ? ? ?p.stdin.close() >>>> ? ? ? ?print elapsed(), i, 'reading' >>>> ? ? ? ?p.stdout.read() >>>> ? ? ? ?print elapsed(), i, 'done' >>>> ? ? ?ts = [Thread(target=go, args=(i,)) for i in xrange(2)] >>>> ? ? ?for t in ts: t.start() >>>> ? ? ?for t in ts: t.join() >>>> >>>> Example output: >>>> >>>> ? ? ?0.001 0 starting >>>> ? ? ?0.003 1 starting >>>> ? ? ?0.005 0 writing >>>> ? ? ?0.016 1 writing >>>> ? ? ?0.093 0 closing >>>> ? ? ?0.093 0 reading >>>> ? ? ?0.094 1 closing >>>> ? ? ?0.094 1 reading >>>> ? ? ?0.098 .. 1 done reading >>>> ? ? ?5.103 1 done >>>> ? ? ?5.108 .. 0 done reading >>>> ? ? 10.113 0 done >>>> >>>> >>> >>> I changed 'python' to the path of python.exe and 'stuckproc.py' to its >>> full path and tried it with Python 2.7 on Windows XP Pro. It worked as >>> expected. >>> >> >> Good point - I didn't specify that I'm seeing this on Linux (Ubuntu >> 10.04's Python 2.6). >> >> > > python test.py ? 0.000 0 starting > ?0.026 0 writing > ?0.026 0 closing > ?0.026 0 reading > ?0.029 .. 0 done reading > ?0.030 1 starting > ?0.038 1 writing > ?0.058 1 closing > ?0.058 1 reading > ?0.061 .. 1 done reading > ?5.026 0 done > ?5.061 1 done > > on debian lenny (Python 2.5) > > JM > FWIW, this is consistently reproduce-able across all the Ubuntu 10.04s I've tried. You may need to increase the message size so that it's large enough for your system. -- Yang Zhang http://yz.mit.edu/ From rpw3 at rpw3.org Wed Feb 9 22:39:08 2011 From: rpw3 at rpw3.org (Rob Warnock) Date: Wed, 09 Feb 2011 21:39:08 -0600 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: Harald Hanche-Olsen wrote: +--------------- | [Icarus Sparry ] | > The 'modern' way to do this is | > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + | | Actually, I think it should be | find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} + | because grep behaves differently when given only one filename as opposed | to several. +--------------- Yup. This is why it's also important to include that "/dev/null" when using "find | xargs", too: find . -maxdepth 2 -name '*.html' -print | xargs grep whatever /dev/null Years & years ago, right after I learned about "xargs", I got burned several times on "find | xargs grep pat" when the file list was long enough that "xargs" fired up more than one "grep"... and the last invocation was given only one arg!! IT FOUND THE PATTERN, BUT DIDN'T TELL ME WHAT !@^%!$@#@! FILE IT WAS IN!! :-{ The trailing "/dev/null" fixes that. ;-} -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From rpw3 at rpw3.org Wed Feb 9 22:47:20 2011 From: rpw3 at rpw3.org (Rob Warnock) Date: Wed, 09 Feb 2011 21:47:20 -0600 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: Harald Hanche-Olsen wrote: +--------------- | [Icarus Sparry ] | > The 'modern' way to do this is | > find . -maxdepth 2 -name '*.html' -exec grep whatever {} + | | Actually, I think it should be | find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} + \; | because grep behaves differently when given only one filename as opposed | to several. +--------------- Oh, wow! I just learned from this thread about the new (to me) "{} +" option to "find"! That wasn't in "find" until relatively recently, it seems. [At least, it wasn't in FreeBSD 4.6, though it seems to be in FreeBSD 6.x and later...] Thanks, guys!! -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From rouslank at msn.com Wed Feb 9 23:02:42 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Wed, 09 Feb 2011 23:02:42 -0500 Subject: inheritance, multiple inheritance and the weaklist and instance dictionaries In-Reply-To: References: <0b752613-0c20-403e-bba9-642ca078a7e8@8g2000prb.googlegroups.com> Message-ID: On 02/09/2011 08:40 PM, Carl Banks wrote: > I explained why in my last post; there's a bunch of reasons. > Generally you can't assume someone's going to go through the type > structure to find the object's dict, nor can you expect inherited > methods to always use the derived class's type structure (some methods > might use their own type's tp_dictoffset or tp_weakreflist, which > would be wrong if called from a superclass that changes those > values). Who do you mean by someone? The code is generated by a program. No human is required to touch it. If it needs to be updated, the program is simply run again with the updated specification file. Thus I can make those assumptions because I have total control over the code. The only thing I don't have control over is the Python code that imports the extension, but in Python, the user doesn't get to choose how they access the weaklist and instance dictionary. > Even if you are careful to avoid such usage, the Python > interpreter can't be sure. So it has to check for layout conflicts, > and these checks would become very complex if it allowed dict and > weakreflist to appear in different locations in the layout (it's have > to check a lot more). What is so complex about this? It already uses "obj_instance + obj_instance->ob_type->tp_weaklistoffset". That's all the checking it needs. It only becomes a problem when trying to derive from two or more classes that already have these defined. In such a case the Python interpreter can't deduce what the values of tp_weaklistoffset and tp_dictoffset in the derived type should be, but it doesn't have to because my program tells it what they need to be. > I would say you do. Python's type system specifies that a derived > type's layout is a superset of its base types' layout. You seem to > have found a way to derive a type without a common layout, perhaps by > exploiting a bug, and you claim to be able to keep data access > straight. But Python types are not intended to work that way, and you > are asking for trouble if you try to do it. I'm not really circumventing this system (except for the varying location of the dictionaries. See the explanation below for that). Python allows variable-sized objects. Tuples and strings are variable sized. This allows them to store the data directly in the object instead of having a pointer to another location in memory. And the objects I generate are basically this: struct MyObject { PyObject_HEAD storage_mode mode; char[x] opaque_data; }; I use the real type instead of char[] when possible because it will have the proper alignment but I still treat it like a private hunk of memory that only my generate code will touch. What I store in opaque_data is up to me. I can store a copy of the wrapped type, or I can store a pointer to it. "mode" specifies what is in opaque_data. A derived type would look like this: struct MyDerivedObject { PyObject_HEAD storage_mode mode; char[y] opaque_data; }; Where y >= x. It's still the same layout. All that's left is some way for the original object to know what C++ type is stored in opaque_data. I could have used another variable like 'mode', but since there is a one-to-one correspondence between PyObject->ob_type and the type that is being wrapped, I can determine the type from ob_type instead. There is no bug being exploited. The actual implementation is a little different than this, but the principle is the same. I said before that the layout varies, but that's only if you consider the contents of opaque_data, but that is neither Python's nor the user's concern. > I guess there's also no point in arguing that tp_dictoffset and > tp_weakreflist need to have the same value for base and derived types, > since you're rejecting the premise that layouts need to be > compatible. Therefore, I'll only point out that the layout checking > code is based on this premise, so that's why you're running afoul of > it. That's not what the Python documentation says. Under http://docs.python.org/c-api/typeobj.html#tp_weaklistoffset it says "This field is inherited by subtypes, but see the rules listed below. A subtype may override this offset; this means that the subtype uses a different weak reference list head than the base type. Since the list head is always found via tp_weaklistoffset, this should not be a problem." And under http://docs.python.org/c-api/typeobj.html#tp_dictoffset it says "This field is inherited by subtypes, but see the rules listed below. A subtype may override this offset; this means that the subtype instances store the dictionary at a difference offset than the base type. Since the dictionary is always found via tp_dictoffset, this should not be a problem." > You claimed in another post you weren't trying to mimic the C++ type > hierarchy in Python, but this line suggests you are. When did I make that claim? Perhaps you misunderstood me I said "I kind-of already did. The issue only comes up when multiply-inheriting from types that have a different combination of the weaklist and instance dictionaries. I don't have to support this particular feature." I was saying I kind-of already did mimic the C++ hierarchy. And when I said "this particular feature", I was talking about the thing I described in the immediately preceding sentence, not the C++ type hierarchy. From tshinnic at io.com Wed Feb 9 23:24:04 2011 From: tshinnic at io.com (Thomas L. Shinnick) Date: Wed, 09 Feb 2011 22:24:04 -0600 Subject: How to Write grep in Emacs Lisp (tutorial) In-Reply-To: References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: <15.E1.00963.668635D4@hrndva-omtalb.mail.rr.com> At 09:39 PM 2/9/2011, Rob Warnock wrote: >Harald Hanche-Olsen wrote: [snip] >Years & years ago, right after I learned about "xargs", I got burned >several times on "find | xargs grep pat" when the file list was long >enough that "xargs" fired up more than one "grep"... and the last >invocation was given only one arg!! IT FOUND THE PATTERN, BUT DIDN'T >TELL ME WHAT !@^%!$@#@! FILE IT WAS IN!! :-{ > >The trailing "/dev/null" fixes that. ;-} I find that I need periodic review of the grep -l -L -h and -H options . I'm surprised when other people forget about these too. The -H option is your heart's desire. >-Rob > >----- >Rob Warnock >627 26th Avenue >San Mateo, CA 94403 (650)572-2607 From jason.swails at gmail.com Thu Feb 10 00:03:00 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 10 Feb 2011 00:03:00 -0500 Subject: Easy function, please help. In-Reply-To: <4D53166D.6050103@mrabarnett.plus.com> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D53166D.6050103@mrabarnett.plus.com> Message-ID: On Wed, Feb 9, 2011 at 5:34 PM, MRAB wrote: > On 09/02/2011 21:42, Jason Swails wrote: > >> You've gotten several good explanations, mainly saying that 0 -> False >> and not 0 -> True, which is why the while loop exits. You've also >> gotten advice about how to make your method more robust (i.e. force >> integer division). >> >> However, as surprising as this may be I'm actually with RR on this one >> (for a little) -- for code readability's sake, you should make your >> conditional more readable (i.e. don't depend on the fact that the >> iterations will take your test value down to 0 which conveniently in >> this case evaluates to False). This could encourage you in later cases >> to think that if this result eventually converged to a different number, >> say the multiplicative identity instead, that the same approach will >> work (when instead it'll dump you into an infinite loop). >> >> You've also gotten the suggestion of typecasting to a string and then >> looking at the number of characters in the string. This works fine for >> integers and positive numbers, but not so well for negatives and floats, >> since both the decimal and negative sign will be counted. You could >> typecast to a string then strip out '-' and '.' and then count the >> characters. i.e. >> >> def num_digits(n): >> return len(str(n).replace('-','').replace('.','')) >> >> Or: > > def num_digits(n): > return len(str(abs(n)).replace('.','')) > > Or typecast to an int if you want to neglect decimals before converting >> to a string, etc. >> >> [snip] > Python doesn't have typecasting. :-) > Because these basic types are not mutable? Most of my work has to be in Fortran, so I'm a relative newcomer to Python. When I don't need Fortran-y performance it's much nicer (obviously to anyone that's used them both)! Still don't know much deeper than Python's cosmetic surface at this point. -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Thu Feb 10 00:26:21 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 10 Feb 2011 00:26:21 -0500 Subject: Easy function, please help. In-Reply-To: <4D533C56.8030804@stoneleaf.us> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> Message-ID: On Wed, Feb 9, 2011 at 8:16 PM, Ethan Furman wrote: > Jason Swails wrote: > >> However, as surprising as this may be I'm actually with RR on this one >> (for a little) -- for code readability's sake, you should make your >> conditional more readable (i.e. don't depend on the fact that the iterations >> will take your test value down to 0 which conveniently in this case >> evaluates to False). >> > > while n: is plenty readable. n is either something or nothing, and > something evaluates to True, nothing to False. > Sure it's readable. But then you have to make sure that the loop will eventually take n down to 0. You can always *assume* that the programmer knew what they were doing (not an assumption I'm typically willing to make on code that's not my own). How is "while n != 0:" any worse? (or abs(n) < tolerance). It has exactly the same effect without adding any code while at the same time directly communicates the intended conditional. IMO it makes reading the code easier to read barring effective documentation (my experience with people documenting their code is that they don't; at least in my field). "while n != 0" makes my life easier. > This could encourage you in later cases to think that if this result >> eventually converged to a different number, say the multiplicative identity >> instead, that the same approach will work [...] >> > > See above comment -- something or nothing, not mathematical identities. The fact that the proposed loop finished with *nothing* was coincidental. What if he had been doing some type of prime factorization or something where each iteration reduced the number until eventually all you were left with was the multiplicative identity? You'd say (correctly) that obviously the same approach won't work, but in some lines of thought it's a logical extension to use the same construct (especially to those that don't fully understand why the original loop exits in the first place). Expanding the conditional a little can only help IMO. > > def num_digits(n): >> return len(str(n).replace('-','').replace('.','')) >> >> Or typecast to an int if you want to neglect decimals before converting to >> a string, etc. >> >> Or use recursion! >> >> >>> def num_digits(n): >> ... if n == 0: >> ... return 0 >> ... else: >> ... return num_digits(n//10) + 1 >> ... >> >>> num_digits(1) >> 1 >> >>> num_digits(0) >> 0 >> > > 0 is still one digit. ;) > Well that is something; yet only nothing evaluates to False. We seem to be at an impasse :). --Jason > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From michele.simionato at gmail.com Thu Feb 10 00:38:11 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 9 Feb 2011 21:38:11 -0800 (PST) Subject: Markdown to reStructuredText Message-ID: Do you know if there is any converter from the Markdown syntax to the rst syntax? Googling for markdown2rst did not help. Thanks! From bjracine at glosten.com Thu Feb 10 01:48:44 2011 From: bjracine at glosten.com (Benjamin J. Racine) Date: Wed, 9 Feb 2011 22:48:44 -0800 Subject: Trying to decide between PHP and Python In-Reply-To: <4d2613ef$0$44009$742ec2ed@news.sonic.net> References: <4d2613ef$0$44009$742ec2ed@news.sonic.net> Message-ID: <7C802104-BB67-4731-9B7E-3DF545948CE4@glosten.com> Cython/Sage is no small undertaking, but I have no idea how to measure relative success between that and hiphop. Ben On Jan 6, 2011, at 11:11 AM, John Nagle wrote: > On 1/4/2011 12:20 PM, Google Poster wrote: >> >> About once a year, I have to learn yet another programming language. >> Given all the recommendations (an outstanding accolade from Bruce >> Eckel, author of "Thinking in Java") I have set my aim to Python. >> Sounds kinda cool. > > If you're just doing simple web-based services, PHP is the > way of least resistance. It's supported by almost all hosting > services. Trying to run Python on shared hosting is generally > painful. Either you're stuck running in CGI, which means you > take the cost of a Python load on every transaction, or you > have to find someone who will let you run long-running > processes so you can run FCGI/WSGI or some Python framework. > > Efforts to compile PHP to hard code have been more successful > than the corresponding efforts for Python. Facebook developed > and uses their HipHop compiler for their huge internal PHP > code base. > > John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list From newsmailcomp6 at gustad.com Thu Feb 10 01:52:34 2011 From: newsmailcomp6 at gustad.com (Petter Gustad) Date: Thu, 10 Feb 2011 07:52:34 +0100 Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: <871v3gpej1.fsf@pangea.home.gustad.com> rpw3 at rpw3.org (Rob Warnock) writes: > invocation was given only one arg!! IT FOUND THE PATTERN, BUT DIDN'T > TELL ME WHAT !@^%!$@#@! FILE IT WAS IN!! :-{ Sounds frustrating, but grep -H will always print the filename, even when given a single filename on the command line. //Petter -- .sig removed by request. From drygalski at googlemail.com Thu Feb 10 01:53:27 2011 From: drygalski at googlemail.com (drygal) Date: Wed, 9 Feb 2011 22:53:27 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> Message-ID: <059aeecd-d98f-4039-89ea-0d31685e6e8f@x1g2000yqb.googlegroups.com> On 9 Lut, 06:29, Michael Hrivnak wrote: > Your function only works if n is an integer. ?Example: > > >>> num_digits(234) > 3 > >>> num_digits(23.4) > > 325 > > When doing integer division, python will throw away the remainder and > return an int. ?Using your example of n==44, 44/10 == 4 and 4/10 == 0 > > Before each iteration of the while loop, the given expression (in this > case just n) is evaluated as a boolean. ?Your function would act the > same if it looked like this: > > def num_digits(n): > ? count = 0 > ? while bool(n): > ? ? ? count = count + 1 > ? ? ? n = n / 10 > ? return count > > 0 of course evaluates to False as a boolean, which is why the while loop stops. > > Just for kicks, this function would work about as well: > > def num_digits(n): > ? ?return len(str(n)) > > And if either of these were a real function you planned to use, you'd > probably want to either cast n as an int ( int(n) ) or at least check > its type: > > if not isinstance(n, int): > ? ?raise TypeError("WTF you didn't pass me an int") > > Michael > > On Wed, Feb 9, 2011 at 12:52 AM, Nanderson > > wrote: > > def num_digits(n): > > ? ?count = 0 > > ? ?while n: > > ? ? ? ?count = count + 1 > > ? ? ? ?n = n / 10 > > ? ?return count > > > This is a function that basically says how many digits are in a > > number. For example, > >>>>print num_digits(44) > > 2 > >>>>print num_digits(7654) > > 4 > > > This function counts the number of decimal digits in a positive > > integer expressed in decimal format. I get this function ALMOST > > completely. The only thing I don't understand is why it eventually > > exits the loop, and goes off to the second branch. "while n" is > > confusing me. What I am thinking is that if someone puts "while n" the > > loop would be infinite. I get what is happening in the function, and I > > understand why this would work, but for some reason it's confusing me > > as to how it is exiting the loop after a certain number of times. Help > > is appreciated, thanks. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > I guess it needs: def num_digits(n): return len(str(n)) -1 or >>> x = lambda a: len(str(a).replace(".","")) >>> x(23.5454) 6 Regards, Damian. From steve+comp.lang.python at pearwood.info Thu Feb 10 01:59:13 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Feb 2011 06:59:13 GMT Subject: Problem with giant font sizes in tkinter Message-ID: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> I have a tkinter application under Python 2.6 which is shows text in a giant font, about twenty(?) times larger than expected. The fonts are set using: titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' On one PC (Fedora), the text is displayed fine. Running xlsfonts gives me this: $ xlsfonts -fn '-Adobe-Helvetica-Bold-R-Normal-*-140-*' -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 On a second PC (Ubuntu), the text is displayed in HUGE letters and I get this from xlsfonts: $ xlsfonts -fn '-Adobe-Helvetica-Bold-R-Normal-*-140-*' -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 I don't know how to diagnose or fix the problem. What should I do to fix this problem? -- Steven From steve+comp.lang.python at pearwood.info Thu Feb 10 02:08:29 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Feb 2011 07:08:29 GMT Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <059aeecd-d98f-4039-89ea-0d31685e6e8f@x1g2000yqb.googlegroups.com> Message-ID: <4d538eed$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 09 Feb 2011 22:53:27 -0800, drygal wrote: > I guess it needs: > > def num_digits(n): > return len(str(n)) -1 I don't think so. >>> num_digits(9) 0 -- Steven From tjreedy at udel.edu Thu Feb 10 02:16:01 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Feb 2011 02:16:01 -0500 Subject: Easy function, please help. In-Reply-To: <0uib28-6aq.ln1@murmur.very.softly> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <0uib28-6aq.ln1@murmur.very.softly> Message-ID: On 2/9/2011 6:00 PM, Rikishi42 wrote: numeric types. > > I would have defined the flaw to be use of '/' for the integer division. Guido agreed, and hence changed it (after much contentious discussion!). -- Terry Jan Reedy From tjreedy at udel.edu Thu Feb 10 02:19:12 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Feb 2011 02:19:12 -0500 Subject: OO Python In-Reply-To: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> References: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Message-ID: On 2/9/2011 4:50 PM, Paul Symonds wrote: > Are there any good resources to learn OO Python from? I learned some from classes in stdlib modules. -- Terry Jan Reedy From daniel at danielstender.com Thu Feb 10 02:24:46 2011 From: daniel at danielstender.com (Daniel Stender) Date: Thu, 10 Feb 2011 08:24:46 +0100 Subject: Markdown to reStructuredText In-Reply-To: References: Message-ID: <4D5392BE.4060805@danielstender.com> http://johnmacfarlane.net/pandoc/ Greetings, DS On 10.02.2011 06:38, Michele Simionato wrote: > Do you know if there is any converter from the Markdown syntax to the > rst syntax? Googling for markdown2rst > did not help. Thanks! From frank at chagford.com Thu Feb 10 02:30:10 2011 From: frank at chagford.com (Frank Millman) Date: Thu, 10 Feb 2011 09:30:10 +0200 Subject: wsgi, ajax, and multiple requests References: Message-ID: Frank Millman wrote: > Hi all > > I have a question about wsgi. > > As far as I can tell from the spec and from the reference implementation, > wsgi requires that each request from the client is responded to by one or > more headers, followed by the response body. It is then ready to handle > the next request. > > 99% of the time this is fine, but I have a situation where I need to vary > this, and I cannot see how to do it. Here is the scenario. > > I am dabbling with writing an ajax-style app. On occasion, I want to send > more than one message from the client to the server. It is important that > the server processes the messages in the same order that they are > generated. I have found that the Safari browser does not always send them > in the correct sequence. > > I found an article on the subject - > > http://www.sitepen.com/blog/2009/02/27/deterministic-clientserver-interaction/ > > It explains that you can never guarantee that the messages will arrive in > the same order, with *any* browser. Maybe I was lucky with the other ones. > It goes on to say that, if the order is important, you must include a > header with a sequential counter, and the server must check the sequence. > If received out of sequence, it must queue the one received, wait for the > correct one, and then process them both in the correct order. > > So the question is, how can I achieve this with wsgi? If I detect that I > have received a request out of sequence, I can queue the request, and send > an empty response. When I receive the correct request, I can process it, > call start_response(), and return the response body, but I cannot figure > out how to get back to process the queued request. > As both client and server are under my control, I have realised that there is a simple solution. On the client side, if there is more than one message to be sent, I pack them into an array, and send them in one request. The server receives the request, unpacks the array, and processes each message in turn. It should work reliably, and I save a round-trip into the bargain. Thanks for the replies - they all help in getting the little grey cells working. Frank From michele.simionato at gmail.com Thu Feb 10 03:03:19 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 10 Feb 2011 00:03:19 -0800 (PST) Subject: Markdown to reStructuredText In-Reply-To: Message-ID: <33e354df-df24-4ca3-bf81-03d19d8a6ea3@glegroupsg2000goo.googlegroups.com> Looks cool, I will have a look at it, thanks! From michele.simionato at gmail.com Thu Feb 10 03:03:19 2011 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 10 Feb 2011 00:03:19 -0800 (PST) Subject: Markdown to reStructuredText In-Reply-To: Message-ID: <33e354df-df24-4ca3-bf81-03d19d8a6ea3@glegroupsg2000goo.googlegroups.com> Looks cool, I will have a look at it, thanks! From benjamin.kaplan at case.edu Thu Feb 10 03:31:41 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 10 Feb 2011 03:31:41 -0500 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D53166D.6050103@mrabarnett.plus.com> Message-ID: On Thu, Feb 10, 2011 at 12:03 AM, Jason Swails wrote: > > > On Wed, Feb 9, 2011 at 5:34 PM, MRAB wrote: >> >> On 09/02/2011 21:42, Jason Swails wrote: >>> >>> You've gotten several good explanations, mainly saying that 0 -> False >>> and not 0 -> True, which is why the while loop exits. ?You've also >>> gotten advice about how to make your method more robust (i.e. force >>> integer division). >>> >>> However, as surprising as this may be I'm actually with RR on this one >>> (for a little) -- for code readability's sake, you should make your >>> conditional more readable (i.e. don't depend on the fact that the >>> iterations will take your test value down to 0 which conveniently in >>> this case evaluates to False). ?This could encourage you in later cases >>> to think that if this result eventually converged to a different number, >>> say the multiplicative identity instead, that the same approach will >>> work (when instead it'll dump you into an infinite loop). >>> >>> You've also gotten the suggestion of typecasting to a string and then >>> looking at the number of characters in the string. ?This works fine for >>> integers and positive numbers, but not so well for negatives and floats, >>> since both the decimal and negative sign will be counted. ?You could >>> typecast to a string then strip out '-' and '.' and then count the >>> characters. ?i.e. >>> >>> def num_digits(n): >>> ? ?return len(str(n).replace('-','').replace('.','')) >>> >> Or: >> >> def num_digits(n): >> ? ?return len(str(abs(n)).replace('.','')) >> >>> Or typecast to an int if you want to neglect decimals before converting >>> to a string, etc. >>> >> [snip] >> Python doesn't have typecasting. :-) > > Because these basic types are not mutable?? Most of my work has to > be in Fortran, so I'm a relative newcomer to Python.? When I don't need > Fortran-y performance it's much nicer (obviously to anyone that's used them > both)!? Still don't know much deeper than Python's cosmetic surface at this > point. > Not exactly. It's because everything in Python is an object. What you're doing isn't type casting. It's just calling an object constructor- no different than any other class in the language. From research at johnohagan.com Thu Feb 10 03:35:24 2011 From: research at johnohagan.com (John O'Hagan) Date: Thu, 10 Feb 2011 08:35:24 +0000 Subject: Reassign or discard Popen().stdout from a server process In-Reply-To: References: Message-ID: <201102100835.25222.research@johnohagan.com> On Wed, 9 Feb 2011, Nobody wrote: > On Fri, 04 Feb 2011 15:48:55 +0000, John O'Hagan wrote: > > But I'm still a little curious as to why even unsuccessfully attempting > > to reassign stdout seems to stop the pipe buffer from filling up. > > It doesn't. If the server continues to run, then it's ignoring/handling > both SIGPIPE and the EPIPE error. Either that, or another process has the > read end of the pipe open (so no SIGPIPE/EPIPE), and the server is using > non-blocking I/O or select() so that it doesn't block writing its > diagnostic messages. The server fails with stdout=PIPE if I don't keep reading it, but doesn't fail if I do stdout=anything (I've tried files, strings, integers, and None) soon after starting the process, without any other changes. How is that consistent with either of the above conditions? I'm sure you're right, I just don't understand. Regards, John From research at johnohagan.com Thu Feb 10 04:12:02 2011 From: research at johnohagan.com (John O'Hagan) Date: Thu, 10 Feb 2011 09:12:02 +0000 Subject: Algorithm for generating pitch-class sets in prime form In-Reply-To: <2011020419320961127-vze26m98@optonlinenet> References: <2011020419320961127-vze26m98@optonlinenet> Message-ID: <201102100912.02709.research@johnohagan.com> On Sat, 5 Feb 2011, Charles Turner wrote: > Hi- > > Do you knowof Christopher Ariza's AthenaCL? > > > > HTH, Charles Wow. That looks like a much more complete and elaborate version of what I'm doing, although from what I can tell I don't think it's real-time. I'll certainly be having a good poke around in the code. Thanks. Mind you, rather than using an algorithm like the one one I was looking for in the OP, AthenaCL uses a dictionary to hold the 12-based prime forms. I want to use arbitrary base-numbers ("temperaments" if applied to pitch), so I'd like to be able to generate the prime forms on the fly. Regards, John From charles.fox at gmail.com Thu Feb 10 05:48:08 2011 From: charles.fox at gmail.com (Charles Fox (Sheffield)) Date: Thu, 10 Feb 2011 02:48:08 -0800 (PST) Subject: PDB how to define a global inspection function? References: <92522ddc-68c3-42a7-8200-042b5b920d2e@g10g2000vbv.googlegroups.com> Message-ID: On Feb 8, 11:37?am, Peter Otten <__pete... at web.de> wrote: > CharlesFox(Sheffield) wrote: > > Hi guys, I'm new to this group and have a question about debugging. > > I'm stepping through my code (using emacs pdbtrack and python-mode.el) > > and would like to isnpect objects as I go. ?So I've defined a little > > object print function, > > > def p(obj): > > ? ? print obj > > ? ? print obj.__class__ > > ? ? d=dir(obj) > > ? ? for a in d: > > ? ? ? ? print a, "=", getattr(obj, a) > > > however it only works if the function is imported by whatever module I > > am currently debugging. ?I'd like it to be available globally so I can > > stop and inspect anything as I step through various modules (including > > external libraries). ?Is there a way to put it in the global scope for > > pdb to use? ? Also is there a way to automatically import it whenever > > pdb starts up (like a matlab startup file)? ? ? (I'm not using ipython > > as it's not happy with pdbtrack in emacs, so am launching from emacs M- > > x pdb command). > > For debugging purposes it's OK to put your function into the __builtin__ > namespace: > > > > >>> def p(): print 42 > ... > >>> import __builtin__ > >>> __builtin__.p = p > > Try it out: > > >>> with open("tmp.py", "w") as f: > > ... ? ? f.write("p()\n") > ...>>> import tmp > > 42 Thanks very much for your help, Peter, that's exactly what I was after :-) Charles From dribnairb at gmail.com Thu Feb 10 08:38:43 2011 From: dribnairb at gmail.com (Brian) Date: Thu, 10 Feb 2011 05:38:43 -0800 (PST) Subject: Yappi error "context not found" Message-ID: I'm posting here because I can't find a Yappi specific mailing list. I've been using the rather brilliant Yappi from http://code.google.com/p/yappi/ It works well for small programs with a few threads. However, when trying to run it over large programs with several hundred threads I've been getting the error "context not found". The most basic example I can come up with which illustrates the problem is below. Changing the number of threads started from 25 down to, say, 10, works fine. Any more than ~25 and the error keeps appearing. This is using Python 2.6.5 and Ubuntu Linux 10.04. I don't have another box to try this out on at the moment. I've tested a similar script using thread.start_new_thread() and that doesn't seem to have the problem. So is there some issue with Yappi and inheriting from threading.Thread? import yappi import time import threading class MyThread(threading.Thread): def run(self): time.sleep(1) yappi.start() for i in range(0,25): c = MyThread() c.start() time.sleep(1) yappi.print_stats() yappi.stop() Running the above gives: [*] [yappi-err] context not found. [*] [yappi-err] context not found. [*] [yappi-err] context not found. [*] [yappi-err] context not found. ... Any help appreciated. From charles.fox at gmail.com Thu Feb 10 09:30:18 2011 From: charles.fox at gmail.com (Charles Fox (Sheffield)) Date: Thu, 10 Feb 2011 06:30:18 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes Message-ID: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> Hi guys, I'm working on debugging a large python simulation which begins by preloading a huge cache of data. I want to step through code on many runs to do the debugging. Problem is that it takes 20 seconds to load the cache at each launch. (Cache is a dict in a 200Mb cPickle binary file). So speed up the compile-test cycle I'm thinking about running a completely separate process (not a fork, but a processed launched form a different terminal) that can load the cache once then dunk it in an area of shareed memory. Each time I debug the main program, it can start up quickly and read from the shared memory instead of loading the cache itself. But when I look at posix_ipc and POSH it looks like you have to fork the second process from the first one, rather than access the shared memory though a key ID as in standard C unix shared memory. Am I missing something? Are there any other ways to do this? thanks, Charles From jason.swails at gmail.com Thu Feb 10 09:50:18 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 10 Feb 2011 09:50:18 -0500 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D53166D.6050103@mrabarnett.plus.com> Message-ID: On Thu, Feb 10, 2011 at 3:31 AM, Benjamin Kaplan wrote: > > > On Wed, Feb 9, 2011 at 5:34 PM, MRAB wrote: > > >>> Or typecast to an int if you want to neglect decimals before converting > >>> to a string, etc. > >>> > >> [snip] > >> Python doesn't have typecasting. :-) > > > > Because these basic types are not mutable? Most of my work has > to > > be in Fortran, so I'm a relative newcomer to Python. When I don't need > > Fortran-y performance it's much nicer (obviously to anyone that's used > them > > both)! Still don't know much deeper than Python's cosmetic surface at > this > > point. > > > > Not exactly. It's because everything in Python is an object. What > you're doing isn't type casting. It's just calling an object > constructor- no different than any other class in the language. > Ah, makes sense, thanks. Most of what I see/work in is C and Fortran -- not much OOP there :) --Jason -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From calderone.jeanpaul at gmail.com Thu Feb 10 10:43:54 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 10 Feb 2011 07:43:54 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> Message-ID: <8e97c42b-1c5c-4144-bb53-79163d183cfe@z3g2000prz.googlegroups.com> On Feb 10, 9:30?am, "Charles Fox (Sheffield)" wrote: > Hi guys, > I'm working on debugging a large python simulation which begins by > preloading a huge cache of data. ?I want to step through code on many > runs to do the debugging. ? Problem is that it takes 20 seconds to > load the cache at each launch. ?(Cache is a dict in a 200Mb cPickle > binary file). > > So speed up the compile-test cycle I'm thinking about running a > completely separate process (not a fork, but a processed launched form > a different terminal) Why _not_ fork? Load up your data, then go into a loop forking and loading/ running the rest of your code in the child. This should be really easy to implement compared to doing something with shared memory, and solves the problem you're trying to solve of long startup time just as well. It also protects you from possible bugs where the data gets corrupted by the code that operates on it, since there's only one copy shared amongst all your tests. Is there some other benefit that the shared memory approach gives you? Of course, adding unit tests that exercise your code on a smaller data set might also be a way to speed up development. Jean-Paul From cousinstanley at gmail.com Thu Feb 10 10:48:47 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 10 Feb 2011 15:48:47 +0000 (UTC) Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I have a tkinter application under Python 2.6 which is shows text > in a giant font, about twenty(?) times larger than expected. > > The fonts are set using: > > titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' > buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > .... Although I've been a linux user for several years, that type of font spec hurts my head .... :-) Will the more simplistic type of tuple spec not work in your tkinter application ? canv.create_text( 81 , 27 , text = ' NTSC Standard ' , fill = 'white' , font = ( 'Helvetica' , 12 , 'bold' ) ) -- Stanley C. Kitching Human Being Phoenix, Arizona From spam at uce.gov Thu Feb 10 10:51:07 2011 From: spam at uce.gov (spam at uce.gov) Date: Thu, 10 Feb 2011 08:51:07 -0700 Subject: email.encoders.encode_base64 creates one line only In-Reply-To: References: Message-ID: > This is with python 3.1.2 (r312:79147). I have not tried with 2.7. > > When I create an attachment with email.mime.image.MIMEImage, by default it > uses email.encoders.encode_base64 for the encoder, but that results in a > single line base64 string, instead of the recommended multiple 76-chars lines. > > This works with most MTA and MUA, but some of them choke on it. > In case somebody runs into the same issue: http://bugs.python.org/issue9298 And I added a work around if you need a solution before this bug is fixed at: http://bugs.python.org/issue11156#msg128213 -- Yves. http://www.SollerS.ca/ http://blog.zioup.org/ From drsalists at gmail.com Thu Feb 10 11:36:29 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 10 Feb 2011 08:36:29 -0800 Subject: OO Python In-Reply-To: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> References: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Message-ID: On Wed, Feb 9, 2011 at 1:50 PM, Paul Symonds wrote: > Are there any good resources to learn OO Python from? Yes, plenty, but it's important for us to know so we can advise you: Do you know any other OO languages yet? From rantingrick at gmail.com Thu Feb 10 11:52:19 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 10 Feb 2011 08:52:19 -0800 (PST) Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <36475556-508d-4459-b558-e1e212b37f48@s11g2000prs.googlegroups.com> On Feb 10, 12:59?am, Steven D'Aprano wrote: > I have a tkinter application under Python 2.6 which is shows text in a > giant font, about twenty(?) times larger than expected. > > The fonts are set using: > > titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' > buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > On one PC (Fedora), the text is displayed fine. Running xlsfonts gives me > this: > > $ xlsfonts -fn '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 > > On a second PC (Ubuntu), the text is displayed in HUGE letters and I get > this from xlsfonts: > > $ xlsfonts -fn '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 > > I don't know how to diagnose or fix the problem. What should I do to fix > this problem? First let me stop laughing... hold on... yea just a minute... a little longer please... gawd i am enjoying this... ok i am ready... *pffftt* ha ha ha ha ha ha ha! I thought you hated Tkinter Steven? That is what you told this fine group many times anyway. Also on many occasions you have said that you have no use for GUI's, period. This is very interesting that know you cannot even draw text to preferred size. Oh, and about your problem. READ THE FREAKING MANUAL! From ethan at stoneleaf.us Thu Feb 10 11:52:38 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 10 Feb 2011 08:52:38 -0800 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> Message-ID: <4D5417D6.2010906@stoneleaf.us> Jason Swails wrote: > On Wed, Feb 9, 2011 at 8:16 PM, Ethan Furman wrote: > while n: is plenty readable. n is either something or nothing, and > something evaluates to True, nothing to False. > > Sure it's readable. But then you have to make sure that the loop will > eventually take n down to 0. Sure, but the same holds true with 'while n != 0' -- you have to make sure the loop will eventually take n down to 0. > You can always *assume* that the > programmer knew what they were doing (not an assumption I'm typically > willing to make on code that's not my own). Hopefully not something you have to deal with unless you're debugging... > How is "while n != 0:" any worse? (or abs(n) < tolerance). It has > exactly the same effect without adding any code while at the same time > directly communicates the intended conditional. IMO it makes reading > the code easier to read barring effective documentation (my experience > with people documenting their code is that they don't; at least in my > field). "while n != 0" makes my life easier. In that instance (a bunch of mathematical functions), I can easily see using that construct. > The fact that the proposed loop finished with *nothing* was > coincidental. What if he had been doing some type of prime > factorization or something where each iteration reduced the number until > eventually all you were left with was the multiplicative identity? > You'd say (correctly) that obviously the same approach won't work, but > in some lines of thought it's a logical extension to use the same > construct (especially to those that don't fully understand why the > original loop exits in the first place). Expanding the conditional a > little can only help IMO. Thank you for making my argument for me -- you have to understand the tool you are using to make the best use of it. > def num_digits(n): > return len(str(n).replace('-','').replace('.','')) > > Or typecast to an int if you want to neglect decimals before > converting to a string, etc. > > Or use recursion! > > >>> def num_digits(n): > ... if n == 0: > ... return 0 > ... else: > ... return num_digits(n//10) + 1 > ... > >>> num_digits(1) > 1 > >>> num_digits(0) > 0 > > > 0 is still one digit. ;) > > > Well that is something; yet only nothing evaluates to False. We seem to > be at an impasse :). I fail to see how a faulty algorithm puts us at an impasse. To tweak your code: --> def num_digits(n, _first_pass=True): --> if n == 0: --> return int(_first_pass) --> else: --> return num_digits(n//10, _first_pass=False) + 1 correctly handles the special case of zero. To use my style, it would look like: --> def num_digits(n, _first_pass=True): --> if n: --> return num_digits(n//10, _first_pass=False) + 1 --> else: --> return int(_first_pass) And, of course, this only works for non-negative integers. (I'll leave the discussion of whether zero is non-negative to others. ;) As I said earlier, I can see using the 'if n == 0' construct in certain situations, and if the non-zero branch were lengthy I would stick with the first version here. ~Ethan~ From tjreedy at udel.edu Thu Feb 10 12:01:57 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Feb 2011 12:01:57 -0500 Subject: Easy function, please help. In-Reply-To: <4D5417D6.2010906@stoneleaf.us> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> <4D5417D6.2010906@stoneleaf.us> Message-ID: On 2/10/2011 11:52 AM, Ethan Furman wrote: > Jason Swails wrote: >> How is "while n != 0:" any worse? 1. It is redundant, just like 'if bool_value is not False:'. Python programmers should understand the null value idiom. 2. It does 2 comparisons, 1 unneeded, instead of 1. For CPython, it adds 2 unnecessary bytecode instructions and takes longer. >>> from dis import dis >>> def f(n): while n: pass >>> dis(f) 2 0 SETUP_LOOP 10 (to 13) >> 3 LOAD_FAST 0 (n) 6 POP_JUMP_IF_FALSE 12 9 JUMP_ABSOLUTE 3 >> 12 POP_BLOCK >> 13 LOAD_CONST 0 (None) 16 RETURN_VALUE >>> def f(n): while n != 0: pass >>> dis(f) 2 0 SETUP_LOOP 16 (to 19) >> 3 LOAD_FAST 0 (n) 6 LOAD_CONST 1 (0) 9 COMPARE_OP 3 (!=) 12 POP_JUMP_IF_FALSE 18 15 JUMP_ABSOLUTE 3 >> 18 POP_BLOCK >> 19 LOAD_CONST 0 (None) 22 RETURN_VALUE >> It has exactly the same effect without adding any code Untrue, see above. -- Terry Jan Reedy From gleam.uahmed at gmail.com Thu Feb 10 12:06:16 2011 From: gleam.uahmed at gmail.com (uahmed) Date: Thu, 10 Feb 2011 22:06:16 +0500 Subject: Problem with giant font sizes in tkinter Message-ID: Hi , I am new one but ur talked make me laugh too :D , although here is relevant link for you " if Tk cannot come up with an exact match, it tries to find a similar font. If that fails, Tk falls back to a platform-specific default font. Tk's idea of what is "similar enough" probably doesn't correspond to your own view, so you shouldn't rely too much on this feature." http://www.pythonware.com/library/tkinter/introduction/x444-fonts.htm Hope it helps you On Thu, Feb 10, 2011 at 9:55 PM, wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Yappi error "context not found" (Brian) > 2. Re: Markdown to reStructuredText (Michele Simionato) > 3. Shared memory python between two separate shell-launched > processes (Charles Fox (Sheffield)) > 4. Re: Easy function, please help. (Jason Swails) > 5. Re: Shared memory python between two separate shell-launched > processes (Jean-Paul Calderone) > 6. Re: Problem with giant font sizes in tkinter (Cousin Stanley) > 7. Re: email.encoders.encode_base64 creates one line only > (spam at uce.gov) > 8. Re: OO Python (Dan Stromberg) > 9. Re: Easy function, please help. (Ethan Furman) > 10. Re: Problem with giant font sizes in tkinter (rantingrick) > > > ---------- Forwarded message ---------- > From: Brian > To: python-list at python.org > Date: Thu, 10 Feb 2011 05:38:43 -0800 (PST) > Subject: Yappi error "context not found" > I'm posting here because I can't find a Yappi specific mailing list. > > I've been using the rather brilliant Yappi from > http://code.google.com/p/yappi/ > It works well for small programs with a few threads. However, when > trying to run it over large programs with several hundred threads I've > been getting the error "context not found". > > The most basic example I can come up with which illustrates the > problem is below. Changing the number of threads started from 25 down > to, say, 10, works fine. Any more than ~25 and the error keeps > appearing. This is using Python 2.6.5 and Ubuntu Linux 10.04. I don't > have another box to try this out on at the moment. > > I've tested a similar script using thread.start_new_thread() and that > doesn't seem to have the problem. So is there some issue with Yappi > and inheriting from threading.Thread? > > import yappi > import time > import threading > > class MyThread(threading.Thread): > def run(self): > time.sleep(1) > > yappi.start() > > for i in range(0,25): > c = MyThread() > c.start() > time.sleep(1) > > yappi.print_stats() > yappi.stop() > > > Running the above gives: > [*] [yappi-err] context not found. > [*] [yappi-err] context not found. > [*] [yappi-err] context not found. > [*] [yappi-err] context not found. > ... > > Any help appreciated. > > > > ---------- Forwarded message ---------- > From: Michele Simionato > To: comp.lang.python at googlegroups.com > Date: Thu, 10 Feb 2011 00:03:19 -0800 (PST) > Subject: Re: Markdown to reStructuredText > Looks cool, I will have a look at it, thanks! > > > > ---------- Forwarded message ---------- > From: "Charles Fox (Sheffield)" > To: python-list at python.org > Date: Thu, 10 Feb 2011 06:30:18 -0800 (PST) > Subject: Shared memory python between two separate shell-launched processes > Hi guys, > I'm working on debugging a large python simulation which begins by > preloading a huge cache of data. I want to step through code on many > runs to do the debugging. Problem is that it takes 20 seconds to > load the cache at each launch. (Cache is a dict in a 200Mb cPickle > binary file). > > So speed up the compile-test cycle I'm thinking about running a > completely separate process (not a fork, but a processed launched form > a different terminal) that can load the cache once then dunk it in an > area of shareed memory. Each time I debug the main program, it can > start up quickly and read from the shared memory instead of loading > the cache itself. > > But when I look at posix_ipc and POSH it looks like you have to fork > the second process from the first one, rather than access the shared > memory though a key ID as in standard C unix shared memory. Am I > missing something? Are there any other ways to do this? > > thanks, > Charles > > > > ---------- Forwarded message ---------- > From: Jason Swails > To: Benjamin Kaplan > Date: Thu, 10 Feb 2011 09:50:18 -0500 > Subject: Re: Easy function, please help. > > > On Thu, Feb 10, 2011 at 3:31 AM, Benjamin Kaplan > wrote: > >> >> > On Wed, Feb 9, 2011 at 5:34 PM, MRAB >> wrote: >> >> >>> Or typecast to an int if you want to neglect decimals before >> converting >> >>> to a string, etc. >> >>> >> >> [snip] >> >> Python doesn't have typecasting. :-) >> > >> > Because these basic types are not mutable? Most of my work has >> to >> > be in Fortran, so I'm a relative newcomer to Python. When I don't need >> > Fortran-y performance it's much nicer (obviously to anyone that's used >> them >> > both)! Still don't know much deeper than Python's cosmetic surface at >> this >> > point. >> > >> >> Not exactly. It's because everything in Python is an object. What >> you're doing isn't type casting. It's just calling an object >> constructor- no different than any other class in the language. >> > > Ah, makes sense, thanks. Most of what I see/work in is C and Fortran -- > not much OOP there :) > > --Jason > > -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Jason M. Swails > Quantum Theory Project, > University of Florida > Ph.D. Graduate Student > 352-392-4032 > > > ---------- Forwarded message ---------- > From: Jean-Paul Calderone > To: python-list at python.org > Date: Thu, 10 Feb 2011 07:43:54 -0800 (PST) > Subject: Re: Shared memory python between two separate shell-launched > processes > On Feb 10, 9:30 am, "Charles Fox (Sheffield)" > wrote: > > Hi guys, > > I'm working on debugging a large python simulation which begins by > > preloading a huge cache of data. I want to step through code on many > > runs to do the debugging. Problem is that it takes 20 seconds to > > load the cache at each launch. (Cache is a dict in a 200Mb cPickle > > binary file). > > > > So speed up the compile-test cycle I'm thinking about running a > > completely separate process (not a fork, but a processed launched form > > a different terminal) > > Why _not_ fork? Load up your data, then go into a loop forking and > loading/ > running the rest of your code in the child. This should be really > easy to > implement compared to doing something with shared memory, and solves > the > problem you're trying to solve of long startup time just as well. It > also > protects you from possible bugs where the data gets corrupted by the > code > that operates on it, since there's only one copy shared amongst all > your > tests. Is there some other benefit that the shared memory approach > gives > you? > > Of course, adding unit tests that exercise your code on a smaller data > set > might also be a way to speed up development. > > Jean-Paul > > > > ---------- Forwarded message ---------- > From: Cousin Stanley > To: python-list at python.org > Date: Thu, 10 Feb 2011 15:48:47 +0000 (UTC) > Subject: Re: Problem with giant font sizes in tkinter > Steven D'Aprano wrote: > > > I have a tkinter application under Python 2.6 which is shows text > > in a giant font, about twenty(?) times larger than expected. > > > > The fonts are set using: > > > > titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' > > buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > .... > > Although I've been a linux user for several years, > that type of font spec hurts my head .... :-) > > Will the more simplistic type of tuple spec > not work in your tkinter application ? > > canv.create_text( > 81 , 27 , > text = ' NTSC Standard ' , > fill = 'white' , > font = ( 'Helvetica' , 12 , 'bold' ) ) > > > -- > Stanley C. Kitching > Human Being > Phoenix, Arizona > > > > > ---------- Forwarded message ---------- > From: spam at uce.gov > To: python-list at python.org > Date: Thu, 10 Feb 2011 08:51:07 -0700 > Subject: Re: email.encoders.encode_base64 creates one line only > > This is with python 3.1.2 (r312:79147). I have not tried with 2.7. >> >> When I create an attachment with email.mime.image.MIMEImage, by default it >> uses email.encoders.encode_base64 for the encoder, but that results in a >> single line base64 string, instead of the recommended multiple 76-chars >> lines. >> >> This works with most MTA and MUA, but some of them choke on it. >> >> > In case somebody runs into the same issue: > http://bugs.python.org/issue9298 > > And I added a work around if you need a solution before this bug is fixed > at: > http://bugs.python.org/issue11156#msg128213 > > -- > Yves. > http://www.SollerS.ca/ > > http://blog.zioup.org/ > > > > ---------- Forwarded message ---------- > From: Dan Stromberg > To: Paul Symonds > Date: Thu, 10 Feb 2011 08:36:29 -0800 > Subject: Re: OO Python > On Wed, Feb 9, 2011 at 1:50 PM, Paul Symonds > wrote: > > Are there any good resources to learn OO Python from? > > Yes, plenty, but it's important for us to know so we can advise you: > Do you know any other OO languages yet? > > > > ---------- Forwarded message ---------- > From: Ethan Furman > To: Jason Swails , python-list at python.org > Date: Thu, 10 Feb 2011 08:52:38 -0800 > Subject: Re: Easy function, please help. > Jason Swails wrote: > >> On Wed, Feb 9, 2011 at 8:16 PM, Ethan Furman wrote: >> while n: is plenty readable. n is either something or nothing, and >> something evaluates to True, nothing to False. >> >> Sure it's readable. But then you have to make sure that the loop will >> eventually take n down to 0. >> > > Sure, but the same holds true with 'while n != 0' -- you have to make sure > the loop will eventually take n down to 0. > > You can always *assume* that the programmer knew what they were doing (not >> an assumption I'm typically willing to make on code that's not my own). >> > > Hopefully not something you have to deal with unless you're debugging... > > How is "while n != 0:" any worse? (or abs(n) < tolerance). It has >> exactly the same effect without adding any code while at the same time >> directly communicates the intended conditional. IMO it makes reading the >> code easier to read barring effective documentation (my experience with >> people documenting their code is that they don't; at least in my field). >> "while n != 0" makes my life easier. >> > > In that instance (a bunch of mathematical functions), I can easily see > using that construct. > > The fact that the proposed loop finished with *nothing* was coincidental. >> What if he had been doing some type of prime factorization or something >> where each iteration reduced the number until eventually all you were left >> with was the multiplicative identity? You'd say (correctly) that obviously >> the same approach won't work, but in some lines of thought it's a logical >> extension to use the same construct (especially to those that don't fully >> understand why the original loop exits in the first place). Expanding the >> conditional a little can only help IMO. >> > > Thank you for making my argument for me -- you have to understand the tool > you are using to make the best use of it. > > def num_digits(n): >> return len(str(n).replace('-','').replace('.','')) >> >> Or typecast to an int if you want to neglect decimals before >> converting to a string, etc. >> >> Or use recursion! >> >> >>> def num_digits(n): >> ... if n == 0: >> ... return 0 >> ... else: >> ... return num_digits(n//10) + 1 >> ... >> >>> num_digits(1) >> 1 >> >>> num_digits(0) >> 0 >> >> >> 0 is still one digit. ;) >> >> >> Well that is something; yet only nothing evaluates to False. We seem to >> be at an impasse :). >> > > I fail to see how a faulty algorithm puts us at an impasse. To tweak your > code: > > --> def num_digits(n, _first_pass=True): > --> if n == 0: > --> return int(_first_pass) > --> else: > --> return num_digits(n//10, _first_pass=False) + 1 > > correctly handles the special case of zero. To use my style, it would look > like: > > --> def num_digits(n, _first_pass=True): > --> if n: > --> return num_digits(n//10, _first_pass=False) + 1 > --> else: > --> return int(_first_pass) > > And, of course, this only works for non-negative integers. (I'll leave the > discussion of whether zero is non-negative to others. ;) As I said > earlier, I can see using the 'if n == 0' construct in certain situations, > and if the non-zero branch were lengthy I would stick with the first version > here. > > ~Ethan~ > > > > ---------- Forwarded message ---------- > From: rantingrick > To: python-list at python.org > Date: Thu, 10 Feb 2011 08:52:19 -0800 (PST) > Subject: Re: Problem with giant font sizes in tkinter > On Feb 10, 12:59 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > > I have a tkinter application under Python 2.6 which is shows text in a > > giant font, about twenty(?) times larger than expected. > > > > The fonts are set using: > > > > titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' > > buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > > > On one PC (Fedora), the text is displayed fine. Running xlsfonts gives me > > this: > > > > $ xlsfonts -fn '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 > > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 > > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 > > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 > > > > On a second PC (Ubuntu), the text is displayed in HUGE letters and I get > > this from xlsfonts: > > > > $ xlsfonts -fn '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 > > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso10646-1 > > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 > > -adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1 > > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 > > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso10646-1 > > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 > > -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 > > > > I don't know how to diagnose or fix the problem. What should I do to fix > > this problem? > > > First let me stop laughing... hold on... yea just a minute... a little > longer please... gawd i am enjoying this... ok i am ready... *pffftt* > ha ha ha ha ha ha ha! > > I thought you hated Tkinter Steven? That is what you told this fine > group many times anyway. Also on many occasions you have said that you > have no use for GUI's, period. This is very interesting that know you > cannot even draw text to preferred size. > > Oh, and about your problem. READ THE FREAKING MANUAL! > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.j.symonds at gmail.com Thu Feb 10 12:11:16 2011 From: paul.j.symonds at gmail.com (Paul Symonds) Date: Thu, 10 Feb 2011 17:11:16 +0000 Subject: OO Python In-Reply-To: References: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Message-ID: <382D8CB0-FE23-4AA7-893F-97405C07E2BF@googlemail.com> I have coded in VB using modules and functions but never coded a complete project in OO. I understand the theory of OO, it's more the syntax and Python nuances that I need to be up to speed on. On 10 Feb 2011, at 16:36, Dan Stromberg wrote: > On Wed, Feb 9, 2011 at 1:50 PM, Paul Symonds wrote: >> Are there any good resources to learn OO Python from? > > Yes, plenty, but it's important for us to know so we can advise you: > Do you know any other OO languages yet? From charles.fox at gmail.com Thu Feb 10 12:21:44 2011 From: charles.fox at gmail.com (Charles Fox (Sheffield)) Date: Thu, 10 Feb 2011 09:21:44 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> <8e97c42b-1c5c-4144-bb53-79163d183cfe@z3g2000prz.googlegroups.com> Message-ID: <5abc8bca-b34a-4df1-bb26-6d1f4ca19b22@d16g2000yqd.googlegroups.com> On Feb 10, 3:43?pm, Jean-Paul Calderone wrote: > On Feb 10, 9:30?am, "Charles Fox (Sheffield)" > wrote: > > > Hi guys, > > I'm working on debugging a large python simulation which begins by > > preloading a huge cache of data. ?I want to step through code on many > > runs to do the debugging. ? Problem is that it takes 20 seconds to > > load the cache at each launch. ?(Cache is a dict in a 200Mb cPickle > > binary file). > > > So speed up the compile-test cycle I'm thinking about running a > > completely separate process (not a fork, but a processed launched form > > a different terminal) > > Why _not_ fork? ?Load up your data, then go into a loop forking and > loading/ > running the rest of your code in the child. ?This should be really > easy to > implement compared to doing something with shared memory, and solves > the > problem you're trying to solve of long startup time just as well. ?It > also > protects you from possible bugs where the data gets corrupted by the > code > that operates on it, since there's only one copy shared amongst all > your > tests. ?Is there some other benefit that the shared memory approach > gives > you? > > Of course, adding unit tests that exercise your code on a smaller data > set > might also be a way to speed up development. > > Jean-Paul Thanks Jean-Paul, I'll have a think about this. I'm not sure if it will get me exactly what I want though, as I would need to keep unloading my development module and reloading it, all within the forked process, and I don't see how my debugger (and emacs pdb tracking) will keep up with that to let me step though the code. (this debugging is more about integration issues than single functions, I have a bunch of unit tests for the little bits but something is unhappy when I put them all together...) (I also had a reply by email, suggesting I use /dev/shm to store the data instead of the hard disc; this speeds things up a little but not much as the data still has to be transferred in bulk into my process. Unless I'm missing something and my process can just access the data in that shm without having to load its own copy?) From calderone.jeanpaul at gmail.com Thu Feb 10 13:22:04 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Thu, 10 Feb 2011 10:22:04 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> <8e97c42b-1c5c-4144-bb53-79163d183cfe@z3g2000prz.googlegroups.com> <5abc8bca-b34a-4df1-bb26-6d1f4ca19b22@d16g2000yqd.googlegroups.com> Message-ID: <0b85cc83-2d2c-45af-8c62-ccb0a4fd56a9@n36g2000pre.googlegroups.com> On Feb 10, 12:21?pm, "Charles Fox (Sheffield)" wrote: > On Feb 10, 3:43?pm, Jean-Paul Calderone > wrote: > > > > > > > > > > > On Feb 10, 9:30?am, "Charles Fox (Sheffield)" > > wrote: > > > > Hi guys, > > > I'm working on debugging a large python simulation which begins by > > > preloading a huge cache of data. ?I want to step through code on many > > > runs to do the debugging. ? Problem is that it takes 20 seconds to > > > load the cache at each launch. ?(Cache is a dict in a 200Mb cPickle > > > binary file). > > > > So speed up the compile-test cycle I'm thinking about running a > > > completely separate process (not a fork, but a processed launched form > > > a different terminal) > > > Why _not_ fork? ?Load up your data, then go into a loop forking and > > loading/ > > running the rest of your code in the child. ?This should be really > > easy to > > implement compared to doing something with shared memory, and solves > > the > > problem you're trying to solve of long startup time just as well. ?It > > also > > protects you from possible bugs where the data gets corrupted by the > > code > > that operates on it, since there's only one copy shared amongst all > > your > > tests. ?Is there some other benefit that the shared memory approach > > gives > > you? > > > Of course, adding unit tests that exercise your code on a smaller data > > set > > might also be a way to speed up development. > > > Jean-Paul > > Thanks Jean-Paul, I'll have a think about this. ?I'm not sure if it > will get me exactly what I want though, as I would need to keep > unloading my development module and reloading it, all within the > forked process, and I don't see how my debugger (and emacs pdb > tracking) will keep up with that to let me step though the code. Not really. Don't load your code at all in the parent. Then there's nothing to unload in each child process, just some code to load for the very first time ever (as far as that process is concerned). Jean-Paul From jason.swails at gmail.com Thu Feb 10 14:04:46 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 10 Feb 2011 14:04:46 -0500 Subject: Problem with giant font sizes in tkinter In-Reply-To: <36475556-508d-4459-b558-e1e212b37f48@s11g2000prs.googlegroups.com> References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <36475556-508d-4459-b558-e1e212b37f48@s11g2000prs.googlegroups.com> Message-ID: On Thu, Feb 10, 2011 at 11:52 AM, rantingrick wrote: > > Oh, and about your problem. READ THE FREAKING MANUAL! > > Google Translation: i have no clue -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Thu Feb 10 14:47:24 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 10 Feb 2011 11:47:24 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> <4D5417D6.2010906@stoneleaf.us> Message-ID: On Feb 10, 11:01?am, Terry Reedy wrote: > On 2/10/2011 11:52 AM, Ethan Furman wrote: > > > Jason Swails wrote: > >> How is "while n != 0:" any worse? > > 1. It is redundant, just like 'if bool_value is not False:'. > Python programmers should understand the null value idiom. > > 2. It does 2 comparisons, 1 unneeded, instead of 1. For CPython, > it adds 2 unnecessary bytecode instructions and takes longer. > > ?>>> from dis import dis > ?>>> def f(n): > ? ? ? ? while n: pass > > ?>>> dis(f) > ? ?2 ? ? ? ? ? 0 SETUP_LOOP ? ? ? ? ? ? ?10 (to 13) > ? ? ? ? ?>> ? ?3 LOAD_FAST ? ? ? ? ? ? ? ?0 (n) > ? ? ? ? ? ? ? ?6 POP_JUMP_IF_FALSE ? ? ? 12 > ? ? ? ? ? ? ? ?9 JUMP_ABSOLUTE ? ? ? ? ? ?3 > ? ? ? ? ?>> ? 12 POP_BLOCK > ? ? ? ? ?>> ? 13 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ? 16 RETURN_VALUE > ?>>> def f(n): > ? ? ? ? while n != 0: pass > > ?>>> dis(f) > ? ?2 ? ? ? ? ? 0 SETUP_LOOP ? ? ? ? ? ? ?16 (to 19) > ? ? ? ? ?>> ? ?3 LOAD_FAST ? ? ? ? ? ? ? ?0 (n) > ? ? ? ? ? ? ? ?6 LOAD_CONST ? ? ? ? ? ? ? 1 (0) > ? ? ? ? ? ? ? ?9 COMPARE_OP ? ? ? ? ? ? ? 3 (!=) > ? ? ? ? ? ? ? 12 POP_JUMP_IF_FALSE ? ? ? 18 > ? ? ? ? ? ? ? 15 JUMP_ABSOLUTE ? ? ? ? ? ?3 > ? ? ? ? ?>> ? 18 POP_BLOCK > ? ? ? ? ?>> ? 19 LOAD_CONST ? ? ? ? ? ? ? 0 (None) > ? ? ? ? ? ? ? 22 RETURN_VALUE > > >> It has exactly the same effect without adding any code > > Untrue, see above. Overblown. See below! Terry i apologize for saying this but you offer a *really* weak argument here. The load constant should only happen once. The COMPARE_OP could be called "an extra step" but such a little problem can easily be optimized away on the CPython side of things. It is obvious that POP_JUMP_IF_FALSE is optimized for boolean comparisons. And even if you throw out my fine solution... 1. When has 2 bytecode instructions EVER out weighed a solid readability feature's incorporation into Python? 2. How many zillions of iterations would it take to notice even a *microscopic* speed reduction? Remember, Python IS "first and foremost" the language of readability. Why do you think indention is enforced? Why do think the number of built-in methods is kept small? Why do think magic methods are wrapped in leading and trailing double underscores? Why do you think the keyword set is simplistic and small? Why? Why? Why? i could go on all day... Terry, *we* are the shining jewel of coherency in a dark sea polluted with multiplicity which is violently agitated by syntactical asininity. From wanderer at dialup4less.com Thu Feb 10 14:57:46 2011 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 10 Feb 2011 11:57:46 -0800 (PST) Subject: Ipython Ctypes conflict Message-ID: When I try to use program that uses ctypes to load a dll in Ipython. I get Traceback (most recent call last): File "... \console.py" line 671, in hook_wrapper_23 res = ensire_str(readline_hook(prompt)) File "...\rlmain.py", lin 342, in readline return self.mode.readline(prompt) File "...\emac.py", line 116, in readline self._print_prompt() File "...\rlmain.py, line 298, in _print_prompt n = c.write_scrolling(self.prompt, self.prompt_color) File "...\console.py", line 289, in write_scrolling w, h = self.size() TypeError: 'NoneType' object is not iterable Readline internal error Some hacking in console.py shows it is caused by def size(self, width=None, height=None): u'''Set/get window size.''' info = CONSOLE_SCREEN_BUFFER_INFO() status = self.GetConsoleScreenBufferInfo(self.hout, byref(info)) if not status: return None if width is not None and height is not None: wmin = info.srWindow.Right - info.srWindow.Left + 1 hmin = info.srWindow.Bottom - info.srWindow.Top + 1 #print wmin, hmin width = max(width, wmin) height = max(height, hmin) #print width, height self.SetConsoleScreenBufferSize(self.hout, self.fixcoord(width, height)) else: return (info.dwSize.X, info.dwSize.Y) After loading the dll, GetConsoleScreenBufferInfo always returns zero, so size returns None and everybody is unhappy. I don't get the problem in Idle or WinPython. From jason.swails at gmail.com Thu Feb 10 15:40:33 2011 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 10 Feb 2011 15:40:33 -0500 Subject: Easy function, please help. In-Reply-To: References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> <4D5417D6.2010906@stoneleaf.us> Message-ID: On Thu, Feb 10, 2011 at 12:01 PM, Terry Reedy wrote: > On 2/10/2011 11:52 AM, Ethan Furman wrote: > > Jason Swails wrote: >> > > > How is "while n != 0:" any worse? >>> >> > 1. It is redundant, just like 'if bool_value is not False:'. > Python programmers should understand the null value idiom. > > 2. It does 2 comparisons, 1 unneeded, instead of 1. For CPython, > it adds 2 unnecessary bytecode instructions and takes longer. > I see what you mean, and I think we're coming from different perspectives. First I must say that the calculations I implement/use are VERY computationally demanding and code optimization is of utmost importance, so this point does not fall on deaf ears. I agree that code optimization can be very important. However, the only things worth *optimizing*, really, is the RDS. Optimizing parts of the program that consume ~5% of the total operation time to run ~20% faster is only ~ 0.1% increase in total performance -- a sacrifice I'm more than willing to make for code readability (as a general philosophy). These programs are also very large, collaborative efforts that necessarily have many people working on it, modifying it, etc. It's this reason why I say that sometimes code readability trumps performance. > It has exactly the same effect without adding any code >>> >> > Untrue, see above. > What I meant was that the function result is unchanged without adding more LOC; not that it was the same on the instruction level. I think this is just a difference of perspective: mine is almost strictly utilitarian, in that I just use languages/code/computers to solve my problems. All the best, Jason > > > -- > Terry Jan Reedy > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Graduate Student 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From w_a_x_man at yahoo.com Thu Feb 10 16:03:01 2011 From: w_a_x_man at yahoo.com (WJ) Date: 10 Feb 2011 21:03:01 GMT Subject: toy list processing problem: collect similar terms References: <87d3s0zioh.fsf@kuiper.lan.informatimago.com> Message-ID: Pascal J. Bourguignon wrote: > Xah Lee writes: > > > > here's a interesting toy list processing problem. > > > > I have a list of lists, where each sublist is labelled by > > a number. I need to collect together the contents of all sublists > > sharing > > the same label. So if I have the list > > > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 > > q r) (5 s t)) > > > > where the first element of each sublist is the label, I need to > > produce: > > > > output: > > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > > > > a Mathematica solution is here: > > http://xahlee.org/UnixResource_dir/writ/notations_mma.html > > > > R5RS Scheme lisp solution: > > http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work > > _gmail.scm by Sourav Mukherjee > > > > also, a Common Lisp solution can be found here: > > http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1d > > ed8824bc750b? > > It's too complex. Just write: > > (let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) > (2 o p) (4 q r) (5 s t)))) > > (mapcar (lambda (class) (reduce (function append) class :key > (function rest))) > (com.informatimago.common-lisp.list:equivalence-classes list :key > (function first))) > > ) > > --> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B)) Clojure: (def groups '((0 a b)(1 c d)(2 e f)(3 g h)(1 i j)(2 k l)(4 m n) (2 o p)(4 q r) (5 s t))) Using group-by: (map (fn[[k v]](flatten (map rest v))) (group-by first groups)) Using reduce: (map #(flatten(rest %)) (reduce (fn[h [k & v]] (merge-with concat h {k v})) {} groups)) From robert.kern at gmail.com Thu Feb 10 16:12:22 2011 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 10 Feb 2011 15:12:22 -0600 Subject: Ipython Ctypes conflict In-Reply-To: References: Message-ID: On 2/10/11 1:57 PM, Wanderer wrote: > When I try to use program that uses ctypes to load a dll in Ipython. The IPython mailing list is over here: http://mail.scipy.org/mailman/listinfo/ipython-dev You can also report bugs here: https://github.com/ipython/ipython/issues -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From bsergean at gmail.com Thu Feb 10 19:26:58 2011 From: bsergean at gmail.com (bsergean) Date: Thu, 10 Feb 2011 16:26:58 -0800 (PST) Subject: Programmatic Parsing of ps References: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> Message-ID: If you're on Linux you should * Have a look at the /proc/ filesystem, there's probably what you want there. Here's a small script that print all the pid/cmd from the process ran with your user. #!/usr/local/bin/python import os import re import stat from os.path import join for pid in (pid for pid in os.listdir('/proc') if re.match('\d', pid)): cmdline_fn = join('/proc', pid, 'cmdline') cmdline = open(cmdline_fn).read() uid = os.stat(cmdline_fn)[stat.ST_UID] if os.getuid() == uid: print pid, cmdline For a more cross-platform solution there's a module that does that (I forgot it's name but with some googling you might find it) On Feb 9, 1:34?pm, Dan Stromberg wrote: > On Wed, Feb 9, 2011 at 11:15 AM, Emile van Sebille wrote: > > > On 2/9/2011 10:58 AM octopusgrabbus said... > > >> I have Python 2.6.6. I would like to get this output > > >> ps -ef | grep 'fglgo csm' > > >> into a list. What is the best way to do that? I've been reading the > >> documentation, and am lost. > > >> Thank you. > >> cmn > > > commands.getoutput > > > Emile > > Also, consider using "ps -eo pid,comm" (or similar) instead of ps -ef > - it should be easier to parse that way. From prologic at shortcircuit.net.au Thu Feb 10 19:46:30 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 11 Feb 2011 10:46:30 +1000 Subject: Programmatic Parsing of ps In-Reply-To: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> References: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> Message-ID: On Thu, Feb 10, 2011 at 4:58 AM, octopusgrabbus wrote: > I have Python 2.6.6. I would like to get this output > > ps -ef | grep 'fglgo csm' > > into a list. What is the best way to do that? I've been reading the > documentation, and am lost. Have you checked out psutil (1) to see if it meets your needs ? cheers James 1. http://pypi.python.org/pypi/psutil/0.2.0 -- -- James Mills -- -- "Problems are solved by method" From drsalists at gmail.com Thu Feb 10 20:06:24 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 10 Feb 2011 17:06:24 -0800 Subject: Programmatic Parsing of ps In-Reply-To: References: <9047160a-9e71-4f7b-bb89-e8cebdc05228@d12g2000vbz.googlegroups.com> Message-ID: FWIW, Linux' /proc is very different from pretty much all other *ix's. I like Linux' design better, but it might be good to put the Linux /proc assumption in one place, in case you need to port to another *ix someday. On Thu, Feb 10, 2011 at 4:26 PM, bsergean wrote: > If you're on Linux you should > > * Have a look at the /proc/ filesystem, there's probably what you want > there. > > Here's a small script that print all the pid/cmd from the process ran > with your user. > > #!/usr/local/bin/python > > import os > import re > import stat > from os.path import join > > for pid in (pid for pid in os.listdir('/proc') if re.match('\d', > pid)): > ? ?cmdline_fn = join('/proc', pid, 'cmdline') > ? ?cmdline = open(cmdline_fn).read() > ? ?uid = os.stat(cmdline_fn)[stat.ST_UID] > > ? ?if os.getuid() == uid: > ? ? ? ?print pid, cmdline > > > For a more cross-platform solution there's a module that does that (I > forgot it's name but with some googling you might find it) > > > > > On Feb 9, 1:34?pm, Dan Stromberg wrote: >> On Wed, Feb 9, 2011 at 11:15 AM, Emile van Sebille wrote: >> >> > On 2/9/2011 10:58 AM octopusgrabbus said... >> >> >> I have Python 2.6.6. I would like to get this output >> >> >> ps -ef | grep 'fglgo csm' >> >> >> into a list. What is the best way to do that? I've been reading the >> >> documentation, and am lost. >> >> >> Thank you. >> >> cmn >> >> > commands.getoutput >> >> > Emile >> >> Also, consider using "ps -eo pid,comm" (or similar) instead of ps -ef >> - it should be easier to parse that way. > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Thu Feb 10 21:08:01 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Feb 2011 02:08:01 GMT Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Feb 2011 15:48:47 +0000, Cousin Stanley wrote: > Steven D'Aprano wrote: > >> I have a tkinter application under Python 2.6 which is shows text in a >> giant font, about twenty(?) times larger than expected. >> >> The fonts are set using: >> >> titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' >> buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' >> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' >> .... > > Although I've been a linux user for several years, that type of font > spec hurts my head .... :-) > > Will the more simplistic type of tuple spec not work in your tkinter > application ? I don't know, but I'll give it a try. Nevertheless, I'd like to learn how to diagnose these sorts of font issues. Can anyone suggest where I should start? -- Steven From steve+comp.lang.python at pearwood.info Thu Feb 10 21:08:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Feb 2011 02:08:37 GMT Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> <4D5417D6.2010906@stoneleaf.us> Message-ID: <4d549a25$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Feb 2011 12:01:57 -0500, Terry Reedy wrote: > On 2/10/2011 11:52 AM, Ethan Furman wrote: >> Jason Swails wrote: > > >>> How is "while n != 0:" any worse? > > 1. It is redundant, just like 'if bool_value is not False:'. Python > programmers should understand the null value idiom. I find that if statement too implicit for my tastes. I prefer to be explicit about the values returned by comparisons, rather than just assume that the reader understands Python's comparisons. Unfortunately, I never know when to stop. if bool_value is not False is True is True is True is True is ... -- Steven From no.email at nospam.invalid Thu Feb 10 21:35:09 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 10 Feb 2011 18:35:09 -0800 Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xhbcb2t9e.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >>> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' >>> .... > Nevertheless, I'd like to learn how to diagnose these sorts of font > issues. Can anyone suggest where I should start? Is the -140- a font size in points (1 point = 1/72 inch) or something like that? Try a smaller number. From rhodri at wildebst.demon.co.uk Thu Feb 10 21:36:14 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 11 Feb 2011 02:36:14 -0000 Subject: OO Python References: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Message-ID: [Re-ordered to get rid of the top-posting] On Thu, 10 Feb 2011 17:11:16 -0000, Paul Symonds wrote: > On 10 Feb 2011, at 16:36, Dan Stromberg wrote: > >> On Wed, Feb 9, 2011 at 1:50 PM, Paul Symonds >> wrote: >>> Are there any good resources to learn OO Python from? >> >> Yes, plenty, but it's important for us to know so we can advise you: >> Do you know any other OO languages yet? > > I have coded in VB using modules and functions but never coded a > complete project in OO. I understand the theory of OO, it's more the > syntax and Python nuances that I need to be up to speed on. On the whole, I'd forget about VB and start with the tutorial at www.python.org. -- Rhodri James *-* Wildebeest Herder to the Masses From steve+comp.lang.python at pearwood.info Thu Feb 10 22:13:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Feb 2011 03:13:25 GMT Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> <7xhbcb2t9e.fsf@ruckus.brouhaha.com> Message-ID: <4d54a955$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Feb 2011 18:35:09 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >>>> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' .... >> Nevertheless, I'd like to learn how to diagnose these sorts of font >> issues. Can anyone suggest where I should start? > > Is the -140- a font size in points (1 point = 1/72 inch) or something > like that? Try a smaller number. Thanks, but I already know how to make random changes to code until it works :) I want to understand what I'm doing and why. Why does the same piece of code work perfectly fine on one PC, and blow up to the size of a house on another? This surprises me, particularly since the not-working PC has the same fonts as the working one (plus extras). -- Steven From rantingrick at gmail.com Thu Feb 10 22:15:56 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 10 Feb 2011 19:15:56 -0800 (PST) Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <78ecf7ca-d94c-4756-960c-34f4cd1c1091@v7g2000yqh.googlegroups.com> On Feb 10, 8:08?pm, Steven D'Aprano wrote: > On Thu, 10 Feb 2011 15:48:47 +0000, Cousin Stanley wrote: > > ? Will the more simplistic type of tuple spec not work in your tkinter > > ? application ? > > I don't know, but I'll give it a try. > > Nevertheless, I'd like to learn how to diagnose these sorts of font > issues. Can anyone suggest where I should start? I am *seriously* worried about comrade D'Aprano! Either his little sister is using his account or he has completely lost his marbles! Either way i am worried! SERIOUSLY! Steven, are you seriously telling this group that with all your knowledge of Python, CPython, C and many other languages you cannot solve a simple "attack of the Tkinter giant font" bug? You cannot read a tutorial or a manual to find the answer? You cannot use Google? From wuwei23 at gmail.com Thu Feb 10 22:34:36 2011 From: wuwei23 at gmail.com (alex23) Date: Thu, 10 Feb 2011 19:34:36 -0800 (PST) Subject: Easy function, please help. References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> <4D5417D6.2010906@stoneleaf.us> Message-ID: <559d4363-c663-4924-823e-ef5866842985@n16g2000prc.googlegroups.com> rantingrick wrote: > 1. When has 2 bytecode instructions EVER out weighed a solid > readability feature's incorporation into Python? The original point was whether or not the code is identical, which Terry showed it was not. > The load constant should only happen once. The > COMPARE_OP could be called "an extra step" but such a little problem > can easily be optimized away on the CPython side of things. Looking forward to seeing your patch. From anikom15 at gmail.com Thu Feb 10 22:39:17 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 10 Feb 2011 19:39:17 -0800 Subject: Problem with giant font sizes in tkinter In-Reply-To: <4d54a955$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> <7xhbcb2t9e.fsf@ruckus.brouhaha.com> <4d54a955$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1297395557.7602.2.camel@localhost.localdomain> On Fri, 2011-02-11 at 03:13 +0000, Steven D'Aprano wrote: > On Thu, 10 Feb 2011 18:35:09 -0800, Paul Rubin wrote: > > > Steven D'Aprano writes: > >>>> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' .... > >> Nevertheless, I'd like to learn how to diagnose these sorts of font > >> issues. Can anyone suggest where I should start? > > > > Is the -140- a font size in points (1 point = 1/72 inch) or something > > like that? Try a smaller number. > > Thanks, but I already know how to make random changes to code until it > works :) > > I want to understand what I'm doing and why. Why does the same piece of > code work perfectly fine on one PC, and blow up to the size of a house on > another? This surprises me, particularly since the not-working PC has the > same fonts as the working one (plus extras). > > > > -- > Steven It could be DPI. Anyways why would you want to set particular fonts anyways? Odd are there's gonna be someone who doesn't have the font installed. Whenever I've done tkinter programming, which isn't much, I've just stuck with the default font. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdmoores at gmail.com Thu Feb 10 22:40:34 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Thu, 10 Feb 2011 19:40:34 -0800 Subject: How does IDLE do it? Message-ID: I recently wrote some code that prints information about the 'jukugo' used in Japanese newspaper articles. A jukugo is a Japanese word written with at least 2 kanji. An example of a 2-kanji jukugo is ?? (kiki -- crisis). I found that I could not use my usual IDE to render the Japanese correctly in either the code or the output. But IDLE (version 3.1.2; Windows Vista) does a beautiful job! See screen shots and . (The whole script plus output is at .) I'd like to know how the IDLE developers did this. How can IDLE not have a problem with Japanese using Courier New, Calibri, even Fences or Windings! (For Wingdings, see .) Thanks, Dick Moores From roland.em0001 at googlemail.com Thu Feb 10 23:34:13 2011 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Fri, 11 Feb 2011 06:34:13 +0200 Subject: returning all matching groups with re.search() In-Reply-To: References: Message-ID: <4D54BC45.70408@googlemail.com> Hello, On 02/07/2011 06:26 PM, Mauro Caceres wrote: > >>> import re > >>> help(re.findall) > Help on function findall in module re: > > findall(pattern, string, flags=0) > Return a list of all non-overlapping matches in the string. > If one or more groups are present in the pattern, return a > list of groups; this will be a list of tuples if the pattern > has more than one group. > Empty matches are included in the result. > > >>> re.findall('e','fredbarneybettywilma') > ['e', 'e', 'e'] depending on what is intended the non-overlapping behaviour of findall() may cause some problem: >>> re.findall('.[aeiou].','fredbarneybettywilma') ['red', 'bar', 'ney', 'bet', 'wil'] >>> re.findall('.[aeiouy].','fredbarneybettywilma') ['red', 'bar', 'ney', 'bet', 'tyw'] BR, Roland > > -- > Mauro C?ceres From anikom15 at gmail.com Thu Feb 10 23:36:01 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 10 Feb 2011 20:36:01 -0800 Subject: Easy function, please help. In-Reply-To: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> Message-ID: <1297398961.7602.4.camel@localhost.localdomain> On Tue, 2011-02-08 at 21:52 -0800, Nanderson wrote: > def num_digits(n): > count = 0 > while n: > count = count + 1 > n = n / 10 > return count > > This is a function that basically says how many digits are in a > number. For example, > >>>print num_digits(44) > 2 > >>>print num_digits(7654) > 4 > > This function counts the number of decimal digits in a positive > integer expressed in decimal format. I get this function ALMOST > completely. The only thing I don't understand is why it eventually > exits the loop, and goes off to the second branch. "while n" is > confusing me. What I am thinking is that if someone puts "while n" the > loop would be infinite. I get what is happening in the function, and I > understand why this would work, but for some reason it's confusing me > as to how it is exiting the loop after a certain number of times. Help > is appreciated, thanks. I've become a little annoyed by this thread. Here's a good function that does what you want: def num_digits(n): """Return number of digits in an iteger.""" count = 1 while n: n = n // 10 count += 1 return count -------------- next part -------------- An HTML attachment was scrubbed... URL: From sg552 at hotmail.co.uk Thu Feb 10 23:54:11 2011 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Feb 2011 04:54:11 +0000 Subject: Parameterized functions of no arguments? Message-ID: Hi all Sorry if this is a dumb question, I would guess it's answered in an FAQ somewhere but I haven't been able to find anything that helps. I'm trying to use Tkinter to create a menu whose entries and corresponding commands depend on some list x. I want the menu options to be labelled by the elements of x, and upon selecting an option k I want my program to execute a function f(k). So I tried writing something that schematically looked like this: def f(k): [do something that depends on k] menu = Tkinter.Menu(master, tearoff = 0) for k in x: menu.add_command(label = str(k), command = lambda: f(k)) The trouble is, whenever I open the menu and click on any entry k, instead of evaluating f(k) it always evaluates f(x[-1]). I've also tried this: menu = Tkinter.Menu(master, tearoff = 0) for k in x: def f(): [do something that depends on k] menu.add_command(label = str(k), command = f) and it gives me the same problem. Can anybody suggest a way around this? From sg552 at hotmail.co.uk Fri Feb 11 00:26:18 2011 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Feb 2011 05:26:18 +0000 Subject: Parameterized functions of no arguments? In-Reply-To: References: Message-ID: On 11/02/2011 04:54, Rotwang wrote: > Hi all > > Sorry if this is a dumb question, I would guess it's answered in an FAQ > somewhere but I haven't been able to find anything that helps. I'm > trying to use Tkinter to create a menu whose entries and corresponding > commands depend on some list x. I want the menu options to be labelled > by the elements of x, and upon selecting an option k I want my program > to execute a function f(k). So I tried writing something that > schematically looked like this: > > def f(k): > [do something that depends on k] > > menu = Tkinter.Menu(master, tearoff = 0) > for k in x: > menu.add_command(label = str(k), command = lambda: f(k)) > > The trouble is, whenever I open the menu and click on any entry k, > instead of evaluating f(k) it always evaluates f(x[-1]). I've also tried > this: > > menu = Tkinter.Menu(master, tearoff = 0) > for k in x: > def f(): > [do something that depends on k] > menu.add_command(label = str(k), command = f) Mmmmnngh, that obviously wasn't going to work. Here's something that does work: menu = Tkinter.Menu(master, tearoff = 0) for k in x: def f(j = k): [do something that depends on j] menu.add_command(label = str(k), command = f) Still, I'd like to know if there's a more elegant method for creating a set of functions indexed by an arbitrary list. From ben+python at benfinney.id.au Fri Feb 11 00:42:32 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Feb 2011 16:42:32 +1100 Subject: Parameterized functions of no arguments? References: Message-ID: <87wrl7ktyv.fsf@benfinney.id.au> Rotwang writes: > Here's something that does work: > > menu = Tkinter.Menu(master, tearoff = 0) > for k in x: > def f(j = k): > [do something that depends on j] > menu.add_command(label = str(k), command = f) > > Still, I'd like to know if there's a more elegant method for creating > a set of functions indexed by an arbitrary list. That already seems quite elegant to me. What part is inelegant to your eye? -- \ ?I'm not a bad guy! I work hard, and I love my kids. So why | `\ should I spend half my Sunday hearing about how I'm going to | _o__) Hell?? ?Homer Simpson | Ben Finney From clp2 at rebertia.com Fri Feb 11 00:50:10 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 10 Feb 2011 21:50:10 -0800 Subject: Parameterized functions of no arguments? In-Reply-To: References: Message-ID: On Thu, Feb 10, 2011 at 8:54 PM, Rotwang wrote: > Hi all > > Sorry if this is a dumb question, I would guess it's answered in an FAQ > somewhere but I haven't been able to find anything that helps. I'm trying to > use Tkinter to create a menu whose entries and corresponding commands depend > on some list x. I want the menu options to be labelled by the elements of x, > and upon selecting an option k I want my program to execute a function f(k). > So I tried writing something that schematically looked like this: > > ? ?def f(k): > ? ? ? ?[do something that depends on k] > > ? ?menu = Tkinter.Menu(master, tearoff = 0) > ? ?for k in x: > ? ? ? ?menu.add_command(label = str(k), command = lambda: f(k)) > > The trouble is, whenever I open the menu and click on any entry k, instead > of evaluating f(k) it always evaluates f(x[-1]). I've also tried this: > > ? ?menu = Tkinter.Menu(master, tearoff = 0) > ? ?for k in x: > ? ? ? ?def f(): > ? ? ? ? ? ?[do something that depends on k] > ? ? ? ?menu.add_command(label = str(k), command = f) > > and it gives me the same problem. Can anybody suggest a way around this? It's a well-known problem due to the intricacies of Python's scoping rules. One workaround is: for k in x: def f(k=k): [rest same as before] Basically, the problem is that f() does close over the variable k, but not the particular value of k at the time it was defined; f() looks up the value of k anew each time it's called. But by the time you get around to actually calling f(), the loop has terminated and thus k retains its last value of x[-1]. Default argument values, however, are evaluated only once and at definition-time, thus achieving the intended behavior. Cheers, Chris -- http://blog.rebertia.com From pavlovevidence at gmail.com Fri Feb 11 00:59:30 2011 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 11 Feb 2011 05:59:30 +0000 (UTC) Subject: Parameterized functions of no arguments? References: Message-ID: Rotwang wrote: > On 11/02/2011 04:54, Rotwang wrote: > Mmmmnngh, that obviously wasn't going to work. Here's something that > does work: > > menu = Tkinter.Menu(master, tearoff = 0) > for k in x: > def f(j = k): > [do something that depends on j] > menu.add_command(label = str(k), command = f) > > Still, I'd like to know if there's a more elegant method for creating a > set of functions indexed by an arbitrary list. If you don't want to use keyword arguments you can define a helper function to help create your closure: def create_menu_command(j): def f(): do_something_that_depends_on(j) return f for k in x: menu.add_command(label=str(k),command=create_menu_command(k)) Carl Banks From no.email at nospam.invalid Fri Feb 11 01:19:57 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 10 Feb 2011 22:19:57 -0800 Subject: Parameterized functions of no arguments? References: Message-ID: <7xvd0rm6sy.fsf@ruckus.brouhaha.com> Rotwang writes: > menu = Tkinter.Menu(master, tearoff = 0) > for k in x: > def f(j = k): > [do something that depends on j] > menu.add_command(label = str(k), command = f) > > Still, I'd like to know if there's a more elegant method for creating > a set of functions indexed by an arbitrary list. That is a standard python idiom. These days maybe I'd use partial evaluation: from functools import partial def f(k): whatever... for k in x: menu.add_command(label=str(k), command=partial(f, k)) the "pure" approach would be something like def f(k): whatever... for k in x: menu.add_command(label=str(k), command=(lambda x: lambda: f(x))(k)) From sg552 at hotmail.co.uk Fri Feb 11 01:25:14 2011 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Feb 2011 06:25:14 +0000 Subject: Parameterized functions of no arguments? In-Reply-To: <87wrl7ktyv.fsf@benfinney.id.au> References: <87wrl7ktyv.fsf@benfinney.id.au> Message-ID: On 11/02/2011 05:42, Ben Finney wrote: > Rotwang writes: > >> Here's something that does work: >> >> menu = Tkinter.Menu(master, tearoff = 0) >> for k in x: >> def f(j = k): >> [do something that depends on j] >> menu.add_command(label = str(k), command = f) >> >> Still, I'd like to know if there's a more elegant method for creating >> a set of functions indexed by an arbitrary list. > > That already seems quite elegant to me. Thanks. > What part is inelegant to your eye? I guess the fact that it exploits the way Python evaluates default function arguments to achieve something other than what they were intended for. Still, I see that Chris suggested the same solution (thanks, Chris) so it clearly isn't something that's frowned upon. From sg552 at hotmail.co.uk Fri Feb 11 01:25:35 2011 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Feb 2011 06:25:35 +0000 Subject: Parameterized functions of no arguments? In-Reply-To: References: Message-ID: On 11/02/2011 05:59, Carl Banks wrote: > Rotwang wrote: >> On 11/02/2011 04:54, Rotwang wrote: >> Mmmmnngh, that obviously wasn't going to work. Here's something that >> does work: >> >> menu = Tkinter.Menu(master, tearoff = 0) >> for k in x: >> def f(j = k): >> [do something that depends on j] >> menu.add_command(label = str(k), command = f) >> >> Still, I'd like to know if there's a more elegant method for creating a >> set of functions indexed by an arbitrary list. > > If you don't want to use keyword arguments you can define a helper > function to help create your closure: > > def create_menu_command(j): > def f(): > do_something_that_depends_on(j) > return f > > for k in x: > menu.add_command(label=str(k),command=create_menu_command(k)) Nice, thanks. From cjns1989 at gmail.com Fri Feb 11 01:29:02 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Fri, 11 Feb 2011 01:29:02 -0500 Subject: Problem with giant font sizes in tkinter In-Reply-To: <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110211062901.GA4274@pavo.local> On Thu, Feb 10, 2011 at 09:08:01PM EST, Steven D'Aprano wrote: > On Thu, 10 Feb 2011 15:48:47 +0000, Cousin Stanley wrote: > > > Steven D'Aprano wrote: > > > >> I have a tkinter application under Python 2.6 which is shows text in a > >> giant font, about twenty(?) times larger than expected. > >> > >> The fonts are set using: > >> > >> titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' > >> buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > >> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > >> .... > > > > Although I've been a linux user for several years, that type of font > > spec hurts my head .... :-) > > > > Will the more simplistic type of tuple spec not work in your tkinter > > application ? > > I don't know, but I'll give it a try. > > Nevertheless, I'd like to learn how to diagnose these sorts of font > issues. Can anyone suggest where I should start? First of all, you need to know precisely what the above font name coding means. Chapter 6 of O'Reilly's ?The X Window System's User Guide?, provides a brief but fairly thorough introduction. In relation to your problem, see in particular the discussion of the use of wild cards and such aspects as pixel size and vertical/horizontal resolution. You can download a scanned pdf of this book free of charge here: http://www.archive.org/details/xwindowsytemosf03querarch Have fun, cj From sg552 at hotmail.co.uk Fri Feb 11 01:32:56 2011 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Feb 2011 06:32:56 +0000 Subject: Parameterized functions of no arguments? In-Reply-To: <7xvd0rm6sy.fsf@ruckus.brouhaha.com> References: <7xvd0rm6sy.fsf@ruckus.brouhaha.com> Message-ID: On 11/02/2011 06:19, Paul Rubin wrote: > Rotwang writes: >> menu = Tkinter.Menu(master, tearoff = 0) >> for k in x: >> def f(j = k): >> [do something that depends on j] >> menu.add_command(label = str(k), command = f) >> >> Still, I'd like to know if there's a more elegant method for creating >> a set of functions indexed by an arbitrary list. > > That is a standard python idiom. These days maybe I'd use partial > evaluation: > > from functools import partial > > def f(k): whatever... > > for k in x: > menu.add_command(label=str(k), command=partial(f, k)) functools is new to me, I will look into it. Thanks. > the "pure" approach would be something like > > def f(k): whatever... > > for k in x: > menu.add_command(label=str(k), > command=(lambda x: lambda: f(x))(k)) I don't understand why this works. What is the difference between (lambda x: lambda: f(x))(k) and lambda: f(k) ? From arnodel at gmail.com Fri Feb 11 02:09:32 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 11 Feb 2011 07:09:32 +0000 Subject: Parameterized functions of no arguments? References: <7xvd0rm6sy.fsf@ruckus.brouhaha.com> Message-ID: <87ei7favyr.fsf@gmail.com> Rotwang writes: > On 11/02/2011 06:19, Paul Rubin wrote: >> Rotwang writes: >>> menu = Tkinter.Menu(master, tearoff = 0) >>> for k in x: >>> def f(j = k): >>> [do something that depends on j] >>> menu.add_command(label = str(k), command = f) >>> >>> Still, I'd like to know if there's a more elegant method for creating >>> a set of functions indexed by an arbitrary list. >> >> That is a standard python idiom. These days maybe I'd use partial >> evaluation: >> >> from functools import partial >> >> def f(k): whatever... >> >> for k in x: >> menu.add_command(label=str(k), command=partial(f, k)) > > functools is new to me, I will look into it. Thanks. > > >> the "pure" approach would be something like >> >> def f(k): whatever... >> >> for k in x: >> menu.add_command(label=str(k), >> command=(lambda x: lambda: f(x))(k)) > > I don't understand why this works. What is the difference between > > (lambda x: lambda: f(x))(k) > The value of k is bound to the local variable x; If k is changed later, it doesn't affect the value of x above Note that you can also write it: lambda k=k: f(k) > and > > lambda: f(k) > > ? K not being local, If k is changed later, it does affect the above. -- Arnaud From no.email at nospam.invalid Fri Feb 11 03:07:38 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 11 Feb 2011 00:07:38 -0800 Subject: Parameterized functions of no arguments? References: Message-ID: <7xpqqzc7ud.fsf@ruckus.brouhaha.com> Dennis Lee Bieber writes: >> menu.add_command(label = str(k), command = lambda: f(k)) > I'm not sure, but what effect does > menu.add_command(label=str(k), command = lambda k=k: f(k)) > have on the processing. In the first example, k is a free variable in the lambda, so it's captured from the outer scope when the lambda is evaluated: >>> k = 3 >>> a = lambda: k >>> k = 5 >>> a() 5 In the second example, k is bound as an arg to the lambda when the lambda runs, initialized to the default value supplied when the lambda was created: >>> k = 3 >>> a = lambda k=5: k >>> a() 5 In the weird looking k=k syntax, the "=k" gets k from the outer scope, and uses it as a default value for the function arg that is bound in the function. I.e. if k=3 then lambda k=k: ... is like lambda k=3:... From steve+comp.lang.python at pearwood.info Fri Feb 11 03:19:00 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Feb 2011 08:19:00 GMT Subject: Parameterized functions of no arguments? References: <7xvd0rm6sy.fsf@ruckus.brouhaha.com> Message-ID: <4d54f0f3$0$29974$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Feb 2011 06:32:56 +0000, Rotwang wrote: > I don't understand why this works. What is the difference between > > (lambda x: lambda: f(x))(k) > > and > > lambda: f(k) > > ? Re-writing them as normal function defs may help. I'm going to do them in reverse order: # lambda: f(k) def func(): return f(k) When you call func() with no arguments, the body is executed and f(k) is returned. Where do f and k come from? At runtime, Python searches the local namespace of func(), and doesn't find either f or k. It then searches the non-local namespace, that is, the function or method that surrounds func (or your lambda), if any. In your case, there is no such nested function, so finally it searches the global namespace, and finds both f and k. But by the time the function is called, the for-loop which sets k has reached the end, and k always has the same value. # (lambda x: lambda: f(x))(k) def func(x): def inner(): return f(x) return inner When you call func(k), it creates a nested function. That nested function includes a "closure", which is a copy of the namespace of func at the time it is called. This closure includes a variable "k". That inner function is returned and saved as the callback function. When you call that callback function, it executes inner(), and f(k) is returned. Where do f and k come from? As normal, Python searches the local namespace, and doesn't find them, but then it finds the variable k in the closure, and *not* the global k that the earlier example would find. This example may help: store = [] for k in range(3): fa = lambda: "k has the value %d" % k fb = (lambda x: lambda: "x has the value %d" % x)(k) print("fa inside the loop", fa()) print("fb inside the loop", fb()) store.append(fa) store.append(fb) for func in store: print("func outside the loop", func()) del k store[1]() # one of the closures store[0]() # one of the non-closures Hope this helps. -- Steven From yanghq at neusoft.com Fri Feb 11 03:19:03 2011 From: yanghq at neusoft.com (yanghq) Date: Fri, 11 Feb 2011 16:19:03 +0800 Subject: [ANN] Pyro 3.11 released In-Reply-To: <4ce9b13a$0$81485$e4fe514c@news.xs4all.nl> References: <4ce9b13a$0$81485$e4fe514c@news.xs4all.nl> Message-ID: <1297412343.2316.56.camel@ocean-desktop> hi, I wanna get attribute value like href,src... in html. for simple html page libxml2dom can help me parse it into dom, and get what I want; but for some pages rendered by js, like: document.write( ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '' ) how can I get the atrribute value of 'src', thank you for any help --------------------------------------------------------------------------------------------------- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. --------------------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From yanghq at neusoft.com Fri Feb 11 03:20:32 2011 From: yanghq at neusoft.com (yanghq) Date: Fri, 11 Feb 2011 16:20:32 +0800 Subject: parse html rendered by js Message-ID: <1297412432.2316.57.camel@ocean-desktop> hi, I wanna get attribute value like href,src... in html. for simple html page libxml2dom can help me parse it into dom, and get what I want; but for some pages rendered by js, like: document.write( ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '' ) how can I get the atrribute value of 'src', thank you for any help. --------------------------------------------------------------------------------------------------- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. --------------------------------------------------------------------------------------------------- From me+list/python at ixokai.io Fri Feb 11 03:35:17 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 11 Feb 2011 00:35:17 -0800 Subject: Problem with giant font sizes in tkinter In-Reply-To: <78ecf7ca-d94c-4756-960c-34f4cd1c1091@v7g2000yqh.googlegroups.com> References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> <78ecf7ca-d94c-4756-960c-34f4cd1c1091@v7g2000yqh.googlegroups.com> Message-ID: <4D54F4C5.6050207@ixokai.io> On 2/10/11 7:15 PM, rantingrick wrote: > I am *seriously* ...blah You are a child. This is your second pointless response to this thread. Part of me wants to say, stop behaving like a 13 year old; only you're behaving worse then several 13 year olds I know. It would be an insult to their maturity to compare you to them. "Grow up" doesn't quite do it. You're usually a troll, everyone gets that. Its all you do, troll here and there, but this is all worse then even what you spew out usually. It's just... kinda, sad. You can't even manage a point anymore. It's kinda funny, really. You've proven yourself incapable of supporting position after position in actual argument-- so now you're just not even able to rant. Once upon a time you would seize upon this and find some reason to rant about-- something, to call to arms the silent majority, to declare you the spokesman for all that is holy and proper and good, none of which can be found here. Now.. this? Lol. Time to change your name. You're no longer Ranting Rick. Congratulations! You're now Blabbering Rick. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From me+list/python at ixokai.io Fri Feb 11 03:45:59 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 11 Feb 2011 00:45:59 -0800 Subject: Easy function, please help. In-Reply-To: <559d4363-c663-4924-823e-ef5866842985@n16g2000prc.googlegroups.com> References: <8e0efff7-4d38-4a85-9653-2178388603d4@y36g2000pra.googlegroups.com> <87oc6l8z1y.fsf@rudin.co.uk> <4D533C56.8030804@stoneleaf.us> <4D5417D6.2010906@stoneleaf.us> <559d4363-c663-4924-823e-ef5866842985@n16g2000prc.googlegroups.com> Message-ID: <4D54F747.4090400@ixokai.io> On 2/10/11 7:34 PM, alex23 wrote: > rantingrick wrote: >> 1. When has 2 bytecode instructions EVER out weighed a solid >> readability feature's incorporation into Python? > > The original point was whether or not the code is identical, which > Terry showed it was not. Rick does not understand what "identical" means. Its a complicated word. "Same" and "exactly the same" and "equivalent" are all also terms of art that are not fully comprehended. Someone says that these two things are the same. Terry points out that they are not, in fact, the same at all. He does not make a value judgment on what is better or not better: or what is preferred or not preferred. He simply points out: they are not the same. Everyone else understands that something may be different from something else, and yet in the end we prefer what is technically slower -- because it is more readable. Everyone else may understand that something may be different from something else, and yet arguing that they are THE SAME is worthy of an objection, because it is simply, factually, wrong. Cue Rick selectively quoting and telling me what it is I'm saying (while utterly proving his inability to read basic English), and righteous indignation about how bad I am as one of the Evil Ones of python-list. Doing... bad things. Badly. Because, I, er, am, bad. Bad. BAD. CUZ. RICK. SAYS. SO. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From ben+python at benfinney.id.au Fri Feb 11 03:55:59 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Feb 2011 19:55:59 +1100 Subject: Parameterized functions of no arguments? References: <87wrl7ktyv.fsf@benfinney.id.au> Message-ID: <87sjvvkl0g.fsf@benfinney.id.au> Rotwang writes: > On 11/02/2011 05:42, Ben Finney wrote: > > What part is inelegant to your eye? > > I guess the fact that it exploits the way Python evaluates default > function arguments to achieve something other than what they were > intended for. I see. If that seems like an exploit, I can see why you think it's inelegant. > Still, I see that Chris suggested the same solution (thanks, Chris) so > it clearly isn't something that's frowned upon. Indeed, in this forum we go to tedious lengths to explain that this behaviour is the case in Python, so code that depends on it may even be encouraged :-) -- \ ?He that loveth father or mother more than me is not worthy of | `\ me: and he that loveth son or daughter more than me is not | _o__) worthy of me.? ?Jesus, as quoted in Matthew 10:37 | Ben Finney From xrgtn at yandex.ru Fri Feb 11 04:52:15 2011 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 11 Feb 2011 11:52:15 +0200 Subject: How to Write grep in Emacs Lisp (tutorial) In-Reply-To: <871v3gpej1.fsf@pangea.home.gustad.com> References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> <871v3gpej1.fsf@pangea.home.gustad.com> Message-ID: <20110211095214.GE21538@xrgtn-q40> Hello, On Thu, Feb 10, 2011 at 07:52:34AM +0100, Petter Gustad wrote: > rpw3 at rpw3.org (Rob Warnock) writes: > > invocation was given only one arg!! IT FOUND > > THE PATTERN, BUT DIDN'T TELL ME WHAT > > !@^%!$@#@! FILE IT WAS IN!! :-{ > > Sounds frustrating, but grep -H will always > print the filename, even when given a single > filename on the command line. not on HP-UX, though. Not even with "export UNIX_STD=2003" P.S. "find ... -exec ... +" works there just fine. -- With best regards, xrgtn From xrgtn at yandex.ru Fri Feb 11 05:06:17 2011 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 11 Feb 2011 12:06:17 +0200 Subject: How to Write grep in Emacs Lisp (tutorial) In-Reply-To: <4d517e15$0$22133$742ec2ed@news.sonic.net> References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: <20110211100617.GF21538@xrgtn-q40> Hello, On Tue, Feb 08, 2011 at 05:32:05PM +0000, Icarus Sparry wrote: > The key thing which makes this 'modern' is the > '+' at the end of the command, rather than '\;'. > This causes find to execute the grep once per > group of files, rather than once per file. many thanks to you, man! I'm surprised to find out that this works on HP-UX B.11.31 and SunOS 5.9 (but not on HP Tru64 UNIX V5.1B). -- With best regards, xrgtn From sg552 at hotmail.co.uk Fri Feb 11 05:32:06 2011 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 11 Feb 2011 10:32:06 +0000 Subject: Parameterized functions of no arguments? In-Reply-To: <4d54f0f3$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <7xvd0rm6sy.fsf@ruckus.brouhaha.com> <4d54f0f3$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/02/2011 08:19, Steven D'Aprano wrote: > > [...] > > Re-writing them as normal function defs may help. I'm going to do them in > reverse order: > > # lambda: f(k) > def func(): > return f(k) > > When you call func() with no arguments, the body is executed and f(k) is > returned. Where do f and k come from? At runtime, Python searches the > local namespace of func(), and doesn't find either f or k. It then > searches the non-local namespace, that is, the function or method that > surrounds func (or your lambda), if any. In your case, there is no such > nested function, so finally it searches the global namespace, and finds > both f and k. But by the time the function is called, the for-loop which > sets k has reached the end, and k always has the same value. > > > > # (lambda x: lambda: f(x))(k) > def func(x): > def inner(): > return f(x) > return inner > > > When you call func(k), it creates a nested function. That nested function > includes a "closure", which is a copy of the namespace of func at the > time it is called. This closure includes a variable "k". > > That inner function is returned and saved as the callback function. When > you call that callback function, it executes inner(), and f(k) is > returned. Where do f and k come from? As normal, Python searches the > local namespace, and doesn't find them, but then it finds the variable k > in the closure, and *not* the global k that the earlier example would > find. > > This example may help: > > store = [] > for k in range(3): > fa = lambda: "k has the value %d" % k > fb = (lambda x: lambda: "x has the value %d" % x)(k) > print("fa inside the loop", fa()) > print("fb inside the loop", fb()) > store.append(fa) > store.append(fb) > > for func in store: > print("func outside the loop", func()) > > del k > > store[1]() # one of the closures > store[0]() # one of the non-closures > > > > > Hope this helps. Indeed it does. Thanks, and likewise to everyone else who replied. From charles.fox at gmail.com Fri Feb 11 05:52:09 2011 From: charles.fox at gmail.com (Charles Fox (Sheffield)) Date: Fri, 11 Feb 2011 02:52:09 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> <8e97c42b-1c5c-4144-bb53-79163d183cfe@z3g2000prz.googlegroups.com> <5abc8bca-b34a-4df1-bb26-6d1f4ca19b22@d16g2000yqd.googlegroups.com> <0b85cc83-2d2c-45af-8c62-ccb0a4fd56a9@n36g2000pre.googlegroups.com> Message-ID: <5f21b17e-c316-41d2-a9c8-861cb4d0e322@e21g2000yqe.googlegroups.com> On Feb 10, 6:22?pm, Jean-Paul Calderone wrote: > On Feb 10, 12:21?pm, "Charles Fox (Sheffield)" > wrote: > > > > > On Feb 10, 3:43?pm, Jean-Paul Calderone > > wrote: > > > > On Feb 10, 9:30?am, "Charles Fox (Sheffield)" > > > wrote: > > > > > Hi guys, > > > > I'm working on debugging a large python simulation which begins by > > > > preloading a huge cache of data. ?I want to step through code on many > > > > runs to do the debugging. ? Problem is that it takes 20 seconds to > > > > load the cache at each launch. ?(Cache is a dict in a 200Mb cPickle > > > > binary file). > > > > > So speed up the compile-test cycle I'm thinking about running a > > > > completely separate process (not a fork, but a processed launched form > > > > a different terminal) > > > > Why _not_ fork? ?Load up your data, then go into a loop forking and > > > loading/ > > > running the rest of your code in the child. ?This should be really > > > easy to > > > implement compared to doing something with shared memory, and solves > > > the > > > problem you're trying to solve of long startup time just as well. ?It > > > also > > > protects you from possible bugs where the data gets corrupted by the > > > code > > > that operates on it, since there's only one copy shared amongst all > > > your > > > tests. ?Is there some other benefit that the shared memory approach > > > gives > > > you? > > > > Of course, adding unit tests that exercise your code on a smaller data > > > set > > > might also be a way to speed up development. > > > > Jean-Paul > > > Thanks Jean-Paul, I'll have a think about this. ?I'm not sure if it > > will get me exactly what I want though, as I would need to keep > > unloading my development module and reloading it, all within the > > forked process, and I don't see how my debugger (and emacs pdb > > tracking) will keep up with that to let me step though the code. > > Not really. ?Don't load your code at all in the parent. ?Then there's > nothing to unload in each child process, just some code to load for > the very first time ever (as far as that process is concerned). > > Jean-Paul Jean, sorry I'm still not sure what you mean, could you give a couple of lines of pseudocode to illustrate it? And explain how my emacs pdbtrack would still be able to pick it up? thanks, charles From askutt at gmail.com Fri Feb 11 06:27:28 2011 From: askutt at gmail.com (Adam Skutt) Date: Fri, 11 Feb 2011 03:27:28 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> Message-ID: <7670aa79-1c60-4adf-8033-6a8e98c202a8@b8g2000vbi.googlegroups.com> On Feb 10, 9:30?am, "Charles Fox (Sheffield)" wrote: > > But when I look at posix_ipc and POSH it looks like you have to fork > the second process from the first one, rather than access the shared > memory though a key ID as in standard C unix shared memory. ?Am I > missing something? ? Are there any other ways to do this? > I don't see what would have given you that impression at all, at least with posix_ipc. It's a straight wrapper on the POSIX shared memory functions, which can be used across processes when used correctly. Even if for some reason that implementation lacks the right stuff, there's always SysV IPC. Open the same segment in both processes, use mmap, and go. What will be tricky, of course, is binding to wherever you stuffed the dictionary. I think ctypes.cast() can do what you need, but I've never done it before. Also, just FYI, there is no such thing as "standard C unix shared memory". There are at least three different relatively widely- supported techniques: SysV, (anonymous) mmap, and POSIX Realtime Shared Memory (which normally involves mmap). All three are standardized by the Open Group, and none of the three are implemented with perfect consistency across Unicies. Adam From nomail at here.net Fri Feb 11 07:40:14 2011 From: nomail at here.net (Sven) Date: Fri, 11 Feb 2011 07:40:14 -0500 Subject: Remove whitespaces and line breaks in a XML file References: <9de1ca25-550d-4591-8255-c07d3e5e7b15@glegroupsg2000goo.googlegroups.com> Message-ID: <2011021107401434600-nomail@herenet> On 2011-02-07 18:46:17 -0500, Josh English said: > I found the code posted at > > http://infix.se/2007/02/06/gentlemen-indent-your-xml > > quite helpful in turning my xml into human-readable structures. It works > best for XML-Data. lxml, which the code is using, already has a pretty_print feature according to this http://codespeak.net/lxml/tutorial.html which would do the same, would it not? -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From alt.mcarter at gmail.com Fri Feb 11 07:52:03 2011 From: alt.mcarter at gmail.com (Mark Carter) Date: Fri, 11 Feb 2011 04:52:03 -0800 (PST) Subject: wx.Frame hidden, and customising the close button Message-ID: <03497879-b376-4d66-8c3b-93fb5b0fbbd3@d16g2000yqd.googlegroups.com> Is there a way of testing whether a frame (suppose I have it as a variable my_frame) is hidden in wxPython? Also, is there a way that I can over-ride the close button so that the frame becomes hidden rather than destroyed, and perform supplementary tests? From calderone.jeanpaul at gmail.com Fri Feb 11 08:24:36 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Fri, 11 Feb 2011 05:24:36 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> <8e97c42b-1c5c-4144-bb53-79163d183cfe@z3g2000prz.googlegroups.com> <5abc8bca-b34a-4df1-bb26-6d1f4ca19b22@d16g2000yqd.googlegroups.com> <0b85cc83-2d2c-45af-8c62-ccb0a4fd56a9@n36g2000pre.googlegroups.com> <5f21b17e-c316-41d2-a9c8-861cb4d0e322@e21g2000yqe.googlegroups.com> Message-ID: <5ac0e264-d789-4de9-9217-97022cfd160a@k18g2000vbq.googlegroups.com> On Feb 11, 5:52?am, "Charles Fox (Sheffield)" wrote: > On Feb 10, 6:22?pm, Jean-Paul Calderone > wrote: > > > > > > > > > > > On Feb 10, 12:21?pm, "Charles Fox (Sheffield)" > > wrote: > > > > On Feb 10, 3:43?pm, Jean-Paul Calderone > > > wrote: > > > > > On Feb 10, 9:30?am, "Charles Fox (Sheffield)" > > > > wrote: > > > > > > Hi guys, > > > > > I'm working on debugging a large python simulation which begins by > > > > > preloading a huge cache of data. ?I want to step through code on many > > > > > runs to do the debugging. ? Problem is that it takes 20 seconds to > > > > > load the cache at each launch. ?(Cache is a dict in a 200Mb cPickle > > > > > binary file). > > > > > > So speed up the compile-test cycle I'm thinking about running a > > > > > completely separate process (not a fork, but a processed launched form > > > > > a different terminal) > > > > > Why _not_ fork? ?Load up your data, then go into a loop forking and > > > > loading/ > > > > running the rest of your code in the child. ?This should be really > > > > easy to > > > > implement compared to doing something with shared memory, and solves > > > > the > > > > problem you're trying to solve of long startup time just as well. ?It > > > > also > > > > protects you from possible bugs where the data gets corrupted by the > > > > code > > > > that operates on it, since there's only one copy shared amongst all > > > > your > > > > tests. ?Is there some other benefit that the shared memory approach > > > > gives > > > > you? > > > > > Of course, adding unit tests that exercise your code on a smaller data > > > > set > > > > might also be a way to speed up development. > > > > > Jean-Paul > > > > Thanks Jean-Paul, I'll have a think about this. ?I'm not sure if it > > > will get me exactly what I want though, as I would need to keep > > > unloading my development module and reloading it, all within the > > > forked process, and I don't see how my debugger (and emacs pdb > > > tracking) will keep up with that to let me step though the code. > > > Not really. ?Don't load your code at all in the parent. ?Then there's > > nothing to unload in each child process, just some code to load for > > the very first time ever (as far as that process is concerned). > > > Jean-Paul > > Jean, sorry I'm still not sure what you mean, could you give a couple > of lines of pseudocode to illustrate it? ? And explain how my emacs > pdbtrack would still be able to pick it up? > thanks, > charles import os import loader data = loader.preload() while True: pid = os.fork() if pid == 0: import program program.main(data) else: os.waitpid(pid, 0) But I won't actually try to predict how this is going to interact with emacs pdbtrack. Jean-Paul From arndt.roger at addcom.de Fri Feb 11 08:30:52 2011 From: arndt.roger at addcom.de (Arndt Roger Schneider) Date: Fri, 11 Feb 2011 14:30:52 +0100 Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano schrieb: > On Thu, 10 Feb 2011 15:48:47 +0000, Cousin Stanley wrote: > > >>Steven D'Aprano wrote: >> >> >>>I have a tkinter application under Python 2.6 which is shows text in a >>>giant font, about twenty(?) times larger than expected. >>> >>>The fonts are set using: >>> >>>titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' >>>buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' >>>labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' >>>.... >> >> Although I've been a linux user for several years, that type of font >> spec hurts my head .... :-) >> >> Will the more simplistic type of tuple spec not work in your tkinter >> application ? > > > I don't know, but I'll give it a try. > > Nevertheless, I'd like to learn how to diagnose these sorts of font > issues. Can anyone suggest where I should start? > > > Those adobe helveticas are bitmap fonts. Tk 8.5 uses freetype to render fonts under X11, if you wish to use outdated bitmap fonts under X11, then disable-xft when building Tk 8.5. I do assume there are different tk versions on your various platforms, and the troubling one is with version 8.5 --8.5 uses anti-aliasing hence freetype. Recommendation: Get rid of bitmap fonts under X11. BTW the default fonts under Linux are: bitstream vera sans (for helvetica) bitstream vera (for times) and bitstream vera sans mono (for courier). In my opion those bitstream fonts are much better than the mentioned Adobe fonts. -roger From vlastimil.brom at gmail.com Fri Feb 11 08:39:24 2011 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 11 Feb 2011 14:39:24 +0100 Subject: wx.Frame hidden, and customising the close button In-Reply-To: <03497879-b376-4d66-8c3b-93fb5b0fbbd3@d16g2000yqd.googlegroups.com> References: <03497879-b376-4d66-8c3b-93fb5b0fbbd3@d16g2000yqd.googlegroups.com> Message-ID: 2011/2/11 Mark Carter : > Is there a way of testing whether a frame (suppose I have it as a > variable my_frame) is hidden in wxPython? > > Also, is there a way that I can over-ride the close button so that the > frame becomes hidden rather than destroyed, and perform supplementary > tests? > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, For testing whether the frame is shown, you can simply use frm.IsShown() >>> my_frame.IsShown() True >>> [here shown with a shell connected to that frame] To intercept closing the window using a clicks on the "x icon" catch the respective event wx.EVT_CLOSE Check the sample e.g. in http://wiki.wxpython.org/wxPython%20by%20Example "Adding an Event Handler" (wxPython-specific questions may be rather discussed on that maillist: http://groups.google.com/group/wxpython-users/topics?pli=1 wxpython-users at googlegroups.com ) hth, vbr From alt.mcarter at gmail.com Fri Feb 11 09:12:31 2011 From: alt.mcarter at gmail.com (Mark Carter) Date: Fri, 11 Feb 2011 06:12:31 -0800 (PST) Subject: wx.Frame hidden, and customising the close button References: <03497879-b376-4d66-8c3b-93fb5b0fbbd3@d16g2000yqd.googlegroups.com> Message-ID: On Feb 11, 1:39?pm, Vlastimil Brom wrote: > (wxPython-specific questions may be rather discussed ?on that maillist:http://groups.google.com/group/wxpython-users/topics?pli=1 Just the ticket! Many thanks! From rdh at new.rr.com Fri Feb 11 09:15:42 2011 From: rdh at new.rr.com (DataSmash) Date: Fri, 11 Feb 2011 06:15:42 -0800 (PST) Subject: Executing functions Message-ID: <353073a6-4597-4b32-b8bf-048ef01a5db1@m27g2000prj.googlegroups.com> Can someone help me understand why Example #1 & Example #2 will run the functions, while Example #3 DOES NOT? Thanks for your time! R.D. def One(): print "running fuction 1" def Two(): print "running fuction 2" def Three(): print "running fuction 3" # Example #1 fList = ["Two()","Three()"] for func in fList: exec func # Example #2 Two() Three() # Example #2 fList = ["Two()","Three()"] for func in fList: func From pruebauno at latinmail.com Fri Feb 11 09:31:58 2011 From: pruebauno at latinmail.com (nn) Date: Fri, 11 Feb 2011 06:31:58 -0800 (PST) Subject: Executing functions References: <353073a6-4597-4b32-b8bf-048ef01a5db1@m27g2000prj.googlegroups.com> Message-ID: <9f0711cd-14e3-4326-ba13-ebf48c80eded@q2g2000pre.googlegroups.com> On Feb 11, 9:15?am, DataSmash wrote: > Can someone help me understand why Example #1 & Example #2 will run > the functions, > while Example #3 DOES NOT? > Thanks for your time! > R.D. > > def One(): > ? ? print "running fuction 1" > def Two(): > ? ? print "running fuction 2" > def Three(): > ? ? print "running fuction 3" > > # Example #1 > fList = ["Two()","Three()"] > for func in fList: > ? ? exec func > > # Example #2 > Two() > Three() > > # Example #2 > fList = ["Two()","Three()"] > for func in fList: > ? ? func Example 1 is executing the code inside strings Example 2 is evaluating two functions and throwing the result away Example 3 is evaluating literals and throwing the result away I don't know why you would expect the third example to run the functions. Maybe running this version will enlighten you: fList = ["random","stuff"] for func in fList: func From andreas.tawn at ubisoft.com Fri Feb 11 09:41:57 2011 From: andreas.tawn at ubisoft.com (Andreas Tawn) Date: Fri, 11 Feb 2011 15:41:57 +0100 Subject: Executing functions In-Reply-To: <353073a6-4597-4b32-b8bf-048ef01a5db1@m27g2000prj.googlegroups.com> References: <353073a6-4597-4b32-b8bf-048ef01a5db1@m27g2000prj.googlegroups.com> Message-ID: <654D9D97DA51AD479973BC2D5578603C0B9CAFE216@PDC-MAIL-CMS01.ubisoft.org> > Can someone help me understand why Example #1 & Example #2 will run > the functions, > while Example #3 DOES NOT? > Thanks for your time! > R.D. > > def One(): > print "running fuction 1" > def Two(): > print "running fuction 2" > def Three(): > print "running fuction 3" > > > # Example #1 > fList = ["Two()","Three()"] > for func in fList: > exec func > > # Example #2 > Two() > Three() > > # Example #3 > fList = ["Two()","Three()"] > for func in fList: > func In example 3, func is a string literal not a function object. Example 1 works because the exec statement parses and then evaluates the func string resulting in the two function calls you see. Try this instead... fList = [One, Two, Three] for func in fList: func() Cheers, Drea From hniksic at xemacs.org Fri Feb 11 09:43:25 2011 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 11 Feb 2011 15:43:25 +0100 Subject: Parameterized functions of no arguments? References: Message-ID: <87bp2izl6a.fsf@xemacs.org> Chris Rebert writes: > It's a well-known problem due to the intricacies of Python's scoping > rules. Actually, it is not specific to Python's scoping rules (which mandate local, then module-level, then built-in name lookup). The root of the surprise is, as you correctly point out, the fact that the variable's "cell" is shared by all iterations through the loop. Taking that into account, it logically follows that all enclosed functions end up reading the same value. This is not endemic to Python, the exact same surprise is present in Common Lisp, a language with long tradition of closures and otherwise radically different scoping rules. * (setq l (loop for i from 1 to 10 collect (lambda () i))) * (mapcar #'funcall l) (11 11 11 11 11 11 11 11 11 11) From alex at moreati.org.uk Fri Feb 11 09:46:01 2011 From: alex at moreati.org.uk (Alex Willmer) Date: Fri, 11 Feb 2011 06:46:01 -0800 (PST) Subject: parse html rendered by js References: Message-ID: On Feb 11, 8:20?am, yanghq wrote: > hi, > ? ? I wanna get attribute value like href,src... in html. > > ? ? for simple html page libxml2dom can help me parse it into dom, and > get what ?I want; > > ? ? but for some pages rendered by js, like: > > document.write( > ' onUnload="end()" onResize="change()">'+ > ? ''+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > ... > ) > how can I get the atrribute value of 'src', thank you for any help. You can - Duplicate the Javascript behaviour in your Python code (i.e. rewrite it yourself). Whenever the javascript changes you will need to update your duplicate code. - Use or write a Python module that uses a web browser to download/ execute the page. I'm not aware of any that exist. Neither option is very good, and that is one reason why such Javascript is considered bad practise. What is your end goal - e.g. testing a web application, screen scraping a web site)? There may be a better way. Alex From ethan at stoneleaf.us Fri Feb 11 09:47:37 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 11 Feb 2011 06:47:37 -0800 Subject: Executing functions In-Reply-To: <353073a6-4597-4b32-b8bf-048ef01a5db1@m27g2000prj.googlegroups.com> References: <353073a6-4597-4b32-b8bf-048ef01a5db1@m27g2000prj.googlegroups.com> Message-ID: <4D554C09.7020800@stoneleaf.us> DataSmash wrote: > Can someone help me understand why Example #1 & Example #2 will run > the functions, > while Example #3 DOES NOT? > Thanks for your time! > R.D. > > def One(): > print "running fuction 1" > def Two(): > print "running fuction 2" > def Three(): > print "running fuction 3" > > > # Example #1 > fList = ["Two()","Three()"] > for func in fList: > exec func In this case, func is set to the strings 'Two()' and 'Three()', then the line tells Python to evaluate the strings and execute them. While this style can be useful, it is also *much* slower than example 2; if all you want is to cycle through the functions, a better way is: --> fList = [Two, Three] --> for func in fList: --> func() > # Example #2 > Two() > Three() The functions Two and Three are called directly > # Example #2 <-- should be 3 :) > fList = ["Two()","Three()"] > for func in fList: > func This is not calling func (no () at the end), and in fact doesn't do anything if called as a script besides evaluate func -- it's a string, but not being assigned anywhere, so unless you are running from the interactive prompt where it will be echoed to screen, nothing happens. ~Ethan~ From premjee07 at gmail.com Fri Feb 11 09:52:58 2011 From: premjee07 at gmail.com (Free Online Jobs) Date: Fri, 11 Feb 2011 06:52:58 -0800 (PST) Subject: Best Way to Earn Online Money with INTERNET, to Make $400 per day at HOME., ., ., ., Message-ID: There are so many ways to earn money .,.,..,.,.,., -- - - -- - http://earnmoney-today.com Earn more money with Internet at home ,.,., Earn money today with Online Jobs .,.,., .,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,., http://earnmoney-today.com ============================================================ From python at mrabarnett.plus.com Fri Feb 11 09:54:47 2011 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 11 Feb 2011 14:54:47 +0000 Subject: returning all matching groups with re.search() In-Reply-To: <4D54BC45.70408@googlemail.com> References: <4D54BC45.70408@googlemail.com> Message-ID: <4D554DB7.105@mrabarnett.plus.com> On 11/02/2011 04:34, Roland Mueller wrote: > Hello, > > On 02/07/2011 06:26 PM, Mauro Caceres wrote: >> >>> import re >> >>> help(re.findall) >> Help on function findall in module re: >> >> findall(pattern, string, flags=0) >> Return a list of all non-overlapping matches in the string. >> If one or more groups are present in the pattern, return a >> list of groups; this will be a list of tuples if the pattern >> has more than one group. >> Empty matches are included in the result. >> >> >>> re.findall('e','fredbarneybettywilma') >> ['e', 'e', 'e'] > > depending on what is intended the non-overlapping behaviour of findall() > may cause some problem: > > >>> re.findall('.[aeiou].','fredbarneybettywilma') > ['red', 'bar', 'ney', 'bet', 'wil'] > > >>> re.findall('.[aeiouy].','fredbarneybettywilma') > ['red', 'bar', 'ney', 'bet', 'tyw'] > Overlapping matches are supported by this regex module: http://pypi.python.org/pypi/regex From mdekauwe at gmail.com Fri Feb 11 09:56:02 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 11 Feb 2011 06:56:02 -0800 (PST) Subject: Class or Dictionary? Message-ID: Hi, I have a series of parameter values which i need to pass throughout my code (>100), in C I would use a structure for example. However in python it is not clear to me if it would be better to use a dictionary or build a class object? Personally I think accessing the values is neater (visually) with an object rather than a dictionary, e.g. x = params['price_of_cats'] * params['price_of_elephants'] vs. x = params.price_of_cats * params.price_of_elephants So currently I am building a series of class objects to hold different parameters and then passing these through my code, e.g. class EmptyObject: pass self.animal_prices = EmptyObject() self.price_of_cats = 12 or reading a file and populating the object I would be keen to hear any reasons why this is a bad approach (if it is, I haven't managed to work this out)? Or perhaps there is a better one? thanks Martin From christian.posta at gmail.com Fri Feb 11 10:06:11 2011 From: christian.posta at gmail.com (christian.posta) Date: Fri, 11 Feb 2011 07:06:11 -0800 (PST) Subject: Asterisk sign before the 'self' keyword Message-ID: I searched quickly to see whether this may have been discussed before, but it's possible my search criteria was not refined enough to get any hits. Forgive me if this is a silly question.. I was reading some Python code from a third-party app for the django project... i saw this in the code and I wasn't certain what it means, nor could I find anything helpful from google. Within the __call__ function for a class, I saw a method of that class referred to like this: *self.() The brackets indicate the method name. What does the *self refer to?? Does it somehow indicate the scope of the 'self' variable? Thanks in advance... From andrea.crotti.0 at gmail.com Fri Feb 11 10:40:10 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 11 Feb 2011 07:40:10 -0800 (PST) Subject: Class or Dictionary? References: Message-ID: <084b8a28-ab97-41ff-a88a-92f5c58c89c4@p11g2000vbq.googlegroups.com> On Feb 11, 3:56?pm, Martin De Kauwe wrote: > Hi, > > I have a series of parameter values which i need to pass throughout my > code (>100), in C I would use a structure for example. However in > python it is not clear to me if it would be better to use a dictionary > or build a class object? Personally I think accessing the values is > neater (visually) with an object rather than a dictionary, e.g. > > x = params['price_of_cats'] * params['price_of_elephants'] > > vs. > > x = params.price_of_cats * params.price_of_elephants Visually neater is not really a good parameter to judge. And in a class you can also overload __getattr__ to get the same syntax as a dictionary. But (>100) parameters seems really a lot, are you sure you can't split in many classes instead? Classes have also the advantage that you can do many things behind the scenes, while with plain dictionaries you can't do much... Where do you take those parameters from and what are they used for? From mdekauwe at gmail.com Fri Feb 11 11:01:40 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 11 Feb 2011 08:01:40 -0800 (PST) Subject: Class or Dictionary? References: <084b8a28-ab97-41ff-a88a-92f5c58c89c4@p11g2000vbq.googlegroups.com> Message-ID: <6be4c7bb-372b-4e75-8b98-7899350d01d5@o18g2000prh.googlegroups.com> On Feb 12, 2:40?am, Andrea Crotti wrote: > On Feb 11, 3:56?pm, Martin De Kauwe wrote: > > > Hi, > > > I have a series of parameter values which i need to pass throughout my > > code (>100), in C I would use a structure for example. However in > > python it is not clear to me if it would be better to use a dictionary > > or build a class object? Personally I think accessing the values is > > neater (visually) with an object rather than a dictionary, e.g. > > > x = params['price_of_cats'] * params['price_of_elephants'] > > > vs. > > > x = params.price_of_cats * params.price_of_elephants > > Visually neater is not really a good parameter to judge. Yes and No. Makes the code easier to read and less picky to type out, in my opinion! But regarding the "no" that is why I posted the question > And in a class you can also overload __getattr__ to get the same > syntax as a dictionary. > But (>100) parameters seems really a lot, are you sure you can't split > in many classes instead? i have a number some are smaller, for example switch/control flags. But the rest can be quite large. I can split them but I don't see the advantage particularly. Currently by using them (e.g. params.rate_of_decomp) it clearly distinguishes in the code this was a model parameter read in from a file. I could create more categories but it just means more names to remember and change in the code. > > Classes have also the advantage that you can do many things behind the > scenes, while with plain dictionaries you can't do much... > Where do you take those parameters from and what are they used for? I have a big model which calculates a process, but this is made up of a number of smaller models. I have coded each of these are separate classes which expect to receive an object e.g. params, or two objects e.g. params and switches. thanks From ian.g.kelly at gmail.com Fri Feb 11 11:02:54 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Feb 2011 09:02:54 -0700 Subject: Asterisk sign before the 'self' keyword In-Reply-To: References: Message-ID: On 2/11/2011 8:06 AM, christian.posta wrote: > I searched quickly to see whether this may have been discussed before, > but it's possible my search criteria was not refined enough to get any > hits. Forgive me if this is a silly question.. > > I was reading some Python code from a third-party app for the django > project... i saw this in the code and I wasn't certain what it means, > nor could I find anything helpful from google. > > Within the __call__ function for a class, I saw a method of that class > referred to like this: > > *self.() > > The brackets indicate the method name. > What does the *self refer to?? > Does it somehow indicate the scope of the 'self' variable? > Thanks in advance... If the line appeared exactly as you have it here, then it would be a syntax error. More likely is that you saw something like this: self.do_something(*self.return_a_sequence()) Here, "return_a_sequence" could return any sequence or iterable. The * indicates that whatever follows it is to be unpacked and passed into "do_something" as a series of individual arguments. For example, if "return_a_sequence" returns the tuple (1, 2, 3), then the above would be functionally equivalent to: self.do_somethign(1, 2, 3) From chris at simplistix.co.uk Fri Feb 11 11:07:35 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 11 Feb 2011 16:07:35 +0000 Subject: TestFixtures 1.9.0 Released! Message-ID: <4D555EC7.1000701@simplistix.co.uk> Hi All, I'm happy to announce a new release of TestFixtures. This release adds a helper for tests of code using zope.component: http://packages.python.org/testfixtures/components.html The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: http://www.simplistix.co.uk/software/python/testfixtures cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From robert.kern at gmail.com Fri Feb 11 11:10:03 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 11 Feb 2011 10:10:03 -0600 Subject: Asterisk sign before the 'self' keyword In-Reply-To: References: Message-ID: On 2/11/11 9:06 AM, christian.posta wrote: > I searched quickly to see whether this may have been discussed before, > but it's possible my search criteria was not refined enough to get any > hits. Forgive me if this is a silly question.. > > I was reading some Python code from a third-party app for the django > project... i saw this in the code and I wasn't certain what it means, > nor could I find anything helpful from google. > > Within the __call__ function for a class, I saw a method of that class > referred to like this: > > *self.() > > The brackets indicate the method name. > What does the *self refer to?? > Does it somehow indicate the scope of the 'self' variable? Can you show the whole statement? Most likely, this was embedded in some other call, e.g.: foo(*self.method()) If this is the case, the * does not bind to "self"; it binds to all of (self.method()), i.e.: foo(*(self.method())) This is just the foo(*args) syntax that unpacks a tuple into individual arguments to pass to foo(). http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From xahlee at gmail.com Fri Feb 11 11:14:14 2011 From: xahlee at gmail.com (Xah Lee) Date: Fri, 11 Feb 2011 08:14:14 -0800 (PST) Subject: How to Write grep in Emacs Lisp (tutorial) References: <22c09fee-f9f4-4692-9a99-f80e4e61ba69@s29g2000pra.googlegroups.com> <87wrlb0wd1.fsf@member.fsf.org> <87mxm6pu39.fsf@pangea.home.gustad.com> <4d517e15$0$22133$742ec2ed@news.sonic.net> Message-ID: <3d1f3888-2b9e-4eba-b078-d80cb433bb23@y30g2000prf.googlegroups.com> On Feb 11, 2:06?am, Alexander Gattin wrote: > Hello, > > On Tue, Feb 08, 2011 at 05:32:05PM +0000, Icarus > > Sparry wrote: > > The key thing which makes this 'modern' is the > > '+' at the end of the command, rather than '\;'. > > This causes find to execute the grep once per > > group of files, rather than once per file. > > many thanks to you, man! > > I'm surprised to find out that this works on HP-UX > B.11.31 and SunOS 5.9 (but not on HP Tru64 UNIX > V5.1B). Is HP-UX still alive? lol. in 2000 i ported our ecommerce web app from Solaris to it. Am not exactly thrilled. At the time, i vaguely recall, the HP sales guys come to us and tells us they have this heart-beat technology ... Xah From osvenskan at gmail.com Fri Feb 11 11:15:03 2011 From: osvenskan at gmail.com (Philip) Date: Fri, 11 Feb 2011 08:15:03 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> <7670aa79-1c60-4adf-8033-6a8e98c202a8@b8g2000vbi.googlegroups.com> Message-ID: On Feb 11, 6:27?am, Adam Skutt wrote: > On Feb 10, 9:30?am, "Charles Fox (Sheffield)" > wrote: > > > But when I look at posix_ipc and POSH it looks like you have to fork > > the second process from the first one, rather than access the shared > > memory though a key ID as in standard C unix shared memory. ?Am I > > missing something? ? Are there any other ways to do this? > > I don't see what would have given you that impression at all, at least > with posix_ipc. ?It's a straight wrapper on the POSIX shared memory > functions, which can be used across processes when used correctly. > Even if for some reason that implementation lacks the right stuff, > there's always SysV IPC. > [some stuff snipped] > Also, just FYI, there is no such thing as "standard C unix shared > memory". ?There are at least three different relatively widely- > supported techniques: SysV, (anonymous) mmap, and POSIX Realtime > Shared Memory (which normally involves mmap). ?All three are > standardized by the Open Group, and none of the three are implemented > with perfect consistency across Unicies. Adam is 100% correct. posix_ipc doesn't require fork. @the OP: Charles, since you refer to "standard" shared memory as being referred to by a key, it sounds like you're thinking of SysV shared memory. POSIX IPC objects are referred to by a string that looks like a filename, e.g. "/my_shared_memory". Note that there's a module called sysv_ipc which is a close cousin of posix_ipc. I'm the author of both. IMO POSIX is easier to use. Cheers Philip From aahz at pythoncraft.com Fri Feb 11 11:49:34 2011 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2011 08:49:34 -0800 Subject: Which non SQL Database ? References: <4d3c8d53$0$44021$742ec2ed@news.sonic.net> Message-ID: In article <4d3c8d53$0$44021$742ec2ed at news.sonic.net>, John Nagle wrote: > > Google's BigTable and Facebook's Cassandra offer impressive >performance at very large scale. But they're way overkill for >a desktop app. Even the midrange systems, like CouchDB, are >far too much machinery for a desktop app. Side note: one reason we chose Cassandra for our "midrange" requirements was that it doesn't have master nodes, and we wanted to avoid single point of failure. Side note 2: do NOT run Cassandra on a virtual machine. That was a bad mistake we made because our performance requirements are fairly modest. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational science. Most reasoning about it is at best rationalization of gut feelings, and at worst plain wrong." --GvR, python-ideas, 2009-03-01 From christian.posta at gmail.com Fri Feb 11 11:57:43 2011 From: christian.posta at gmail.com (christian.posta) Date: Fri, 11 Feb 2011 08:57:43 -0800 (PST) Subject: Asterisk sign before the 'self' keyword References: Message-ID: <269b5697-7e72-4ecc-9265-58a156baedf7@y31g2000prd.googlegroups.com> On Feb 11, 9:10?am, Robert Kern wrote: > On 2/11/11 9:06 AM, christian.posta wrote: > > > > > I searched quickly to see whether this may have been discussed before, > > but it's possible my search criteria was not refined enough to get any > > hits. Forgive me if this is a silly question.. > > > I was reading some Python code from a third-party app for the django > > project... i saw this in the code and I wasn't certain what it means, > > nor could I find anything helpful from google. > > > Within the __call__ function for a class, I saw a method of that class > > referred to like this: > > > *self.() > > > The brackets indicate the method name. > > What does the *self refer to?? > > Does it somehow indicate the scope of the 'self' variable? > > Can you show the whole statement? Most likely, this was embedded in some other > call, e.g.: > > ? ?foo(*self.method()) > > If this is the case, the * does not bind to "self"; it binds to all of > (self.method()), i.e.: > > ? ?foo(*(self.method())) > > This is just the foo(*args) syntax that unpacks a tuple into individual > arguments to pass to foo(). > > http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l... > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco Yep, you are correct! It is indeed part of a larger statement. Sorry for the confusion. Here is the entire snippet: def get_urls(self): # In Django 1.1 and later you can hook this in to your urlconf from django.conf.urls.defaults import patterns return patterns('', *self.get_urlpatterns()) From christian.posta at gmail.com Fri Feb 11 11:57:50 2011 From: christian.posta at gmail.com (christian.posta) Date: Fri, 11 Feb 2011 08:57:50 -0800 (PST) Subject: Asterisk sign before the 'self' keyword References: Message-ID: <6da4b2d7-3b67-4f31-b73f-97df13215bee@k15g2000prk.googlegroups.com> On Feb 11, 9:10?am, Robert Kern wrote: > On 2/11/11 9:06 AM, christian.posta wrote: > > > > > I searched quickly to see whether this may have been discussed before, > > but it's possible my search criteria was not refined enough to get any > > hits. Forgive me if this is a silly question.. > > > I was reading some Python code from a third-party app for the django > > project... i saw this in the code and I wasn't certain what it means, > > nor could I find anything helpful from google. > > > Within the __call__ function for a class, I saw a method of that class > > referred to like this: > > > *self.() > > > The brackets indicate the method name. > > What does the *self refer to?? > > Does it somehow indicate the scope of the 'self' variable? > > Can you show the whole statement? Most likely, this was embedded in some other > call, e.g.: > > ? ?foo(*self.method()) > > If this is the case, the * does not bind to "self"; it binds to all of > (self.method()), i.e.: > > ? ?foo(*(self.method())) > > This is just the foo(*args) syntax that unpacks a tuple into individual > arguments to pass to foo(). > > http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l... > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco Yep, you are correct! It is indeed part of a larger statement. Sorry for the confusion. Here is the entire snippet: def get_urls(self): # In Django 1.1 and later you can hook this in to your urlconf from django.conf.urls.defaults import patterns return patterns('', *self.get_urlpatterns()) From christian.posta at gmail.com Fri Feb 11 11:59:11 2011 From: christian.posta at gmail.com (christian.posta) Date: Fri, 11 Feb 2011 08:59:11 -0800 (PST) Subject: Asterisk sign before the 'self' keyword References: Message-ID: On Feb 11, 9:10?am, Robert Kern wrote: > On 2/11/11 9:06 AM, christian.posta wrote: > > > > > I searched quickly to see whether this may have been discussed before, > > but it's possible my search criteria was not refined enough to get any > > hits. Forgive me if this is a silly question.. > > > I was reading some Python code from a third-party app for the django > > project... i saw this in the code and I wasn't certain what it means, > > nor could I find anything helpful from google. > > > Within the __call__ function for a class, I saw a method of that class > > referred to like this: > > > *self.() > > > The brackets indicate the method name. > > What does the *self refer to?? > > Does it somehow indicate the scope of the 'self' variable? > > Can you show the whole statement? Most likely, this was embedded in some other > call, e.g.: > > ? ?foo(*self.method()) > > If this is the case, the * does not bind to "self"; it binds to all of > (self.method()), i.e.: > > ? ?foo(*(self.method())) > > This is just the foo(*args) syntax that unpacks a tuple into individual > arguments to pass to foo(). > > http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l... > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco Yep, you are correct! It is indeed part of a larger statement. Sorry for the confusion. Here is the entire snippet: def get_urls(self): # In Django 1.1 and later you can hook this in to your urlconf from django.conf.urls.defaults import patterns return patterns('', *self.get_urlpatterns()) From christian.posta at gmail.com Fri Feb 11 11:59:56 2011 From: christian.posta at gmail.com (christian.posta) Date: Fri, 11 Feb 2011 08:59:56 -0800 (PST) Subject: Asterisk sign before the 'self' keyword References: <6da4b2d7-3b67-4f31-b73f-97df13215bee@k15g2000prk.googlegroups.com> Message-ID: On Feb 11, 9:57?am, "christian.posta" wrote: > On Feb 11, 9:10?am, Robert Kern wrote: > > > > > On 2/11/11 9:06 AM, christian.posta wrote: > > > > I searched quickly to see whether this may have been discussed before, > > > but it's possible my search criteria was not refined enough to get any > > > hits. Forgive me if this is a silly question.. > > > > I was reading some Python code from a third-party app for the django > > > project... i saw this in the code and I wasn't certain what it means, > > > nor could I find anything helpful from google. > > > > Within the __call__ function for a class, I saw a method of that class > > > referred to like this: > > > > *self.() > > > > The brackets indicate the method name. > > > What does the *self refer to?? > > > Does it somehow indicate the scope of the 'self' variable? > > > Can you show the whole statement? Most likely, this was embedded in some other > > call, e.g.: > > > ? ?foo(*self.method()) > > > If this is the case, the * does not bind to "self"; it binds to all of > > (self.method()), i.e.: > > > ? ?foo(*(self.method())) > > > This is just the foo(*args) syntax that unpacks a tuple into individual > > arguments to pass to foo(). > > >http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l... > > > -- > > Robert Kern > > > "I have come to believe that the whole world is an enigma, a harmless enigma > > ? that is made terrible by our own mad attempt to interpret it as though it had > > ? an underlying truth." > > ? ?-- Umberto Eco > > Yep, you are correct! > It is indeed part of a larger statement. Sorry for the confusion. > > Here is the entire snippet: > > ? ? def get_urls(self): > ? ? ? ? # In Django 1.1 and later you can hook this in to your urlconf > ? ? ? ? from django.conf.urls.defaults import patterns > ? ? ? ? return patterns('', *self.get_urlpatterns()) Thank you both Ian and Robert. It now makes perfect sense! Thanks!! From subscriptions at cagttraining.com Fri Feb 11 12:02:08 2011 From: subscriptions at cagttraining.com (Bill Felton) Date: Fri, 11 Feb 2011 12:02:08 -0500 Subject: Class or Dictionary? In-Reply-To: References: Message-ID: From an old-time Smalltalker / object guy, take this for whatever it's worth. The *primary* reason for going with a class over a dictionary is if there is specific behavior that goes along with these attributes. If there isn't, if this is "just" an 'object store', there's no reason not to use a dictionary. After all, it is not too far off the mark to say a class is just a dictionary with it's own behavior set... As another poster pointed out, 100 (or more) attributes is an oddity, I would call it a 'code smell'. Whereas a dictionary with 100 entries is no big deal at all. But for me, the big deciding factor comes down to whether or not there is specific behavior associated with this "bundle" of attributes. If yes, class, if no, nothing wrong with dictionary. cheers, Bill On Feb 11, 2011, at 9:56 AM, Martin De Kauwe wrote: > Hi, > > I have a series of parameter values which i need to pass throughout my > code (>100), in C I would use a structure for example. However in > python it is not clear to me if it would be better to use a dictionary > or build a class object? Personally I think accessing the values is > neater (visually) with an object rather than a dictionary, e.g. > > x = params['price_of_cats'] * params['price_of_elephants'] > > vs. > > x = params.price_of_cats * params.price_of_elephants > > So currently I am building a series of class objects to hold different > parameters and then passing these through my code, e.g. > > class EmptyObject: > pass > > self.animal_prices = EmptyObject() > self.price_of_cats = 12 or reading a file and populating the object > > > I would be keen to hear any reasons why this is a bad approach (if it > is, I haven't managed to work this out)? Or perhaps there is a better > one? > > thanks > > Martin > -- > http://mail.python.org/mailman/listinfo/python-list From wdepli at mikrotec.com Fri Feb 11 12:30:04 2011 From: wdepli at mikrotec.com (Doug Epling) Date: Fri, 11 Feb 2011 12:30:04 -0500 Subject: Which non SQL Database ? In-Reply-To: References: Message-ID: On 12/4/2010 5:42 PM, Jorge Biquez wrote: > Hello all. > > Newbie question. Sorry. > > As part of my process to learn python I am working on two personal > applications. Both will do it fine with a simple structure of data > stored in files. I now there are lot of databases around I can use but I > would like to know yoor advice on what other options you would consider > for the job (it is training so no pressure on performance). One > application will run as a desktop one,under Windows, Linux, Macintosh, > being able to update data, not much, not complex, not many records. The > second application, running behind web pages, will do the same, I mean, > process simple data, updating showing data. not much info, not complex. So, why not LDAP? > As an excersice it is more than enough I guess and will let me learn > what I need for now. > Talking with a friend about what he will do (he use C only) he suggest > to take a look on dBase format file since it is a stable format, fast > and the index structure will be fine or maybe go with BD (Berkley) > database file format (I hope I understood this one correctly) . Plain > files it is not an option since I would like to have option to do rapid > searches. > > What would do you suggest to take a look? If possible available under > the 3 plattforms. > > Thanks in advance for your comments. > > Jorge Biquez > From drsalists at gmail.com Fri Feb 11 13:15:27 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 11 Feb 2011 10:15:27 -0800 Subject: Class or Dictionary? In-Reply-To: References: Message-ID: On Fri, Feb 11, 2011 at 6:56 AM, Martin De Kauwe wrote: > Hi, > > I have a series of parameter values which i need to pass throughout my > code (>100), in C I would use a structure for example. However in > python it is not clear to me if it would be better to use a dictionary > or build a class object? Personally I think accessing the values is > neater (visually) with an object rather than a dictionary, e.g. > > x = params['price_of_cats'] * params['price_of_elephants'] > > vs. > > x = params.price_of_cats * params.price_of_elephants > > So currently I am building a series of class objects to hold different > parameters and then passing these through my code, e.g. > > class EmptyObject: > ? ?pass > > self.animal_prices = EmptyObject() > self.price_of_cats = 12 or reading a file and populating the object > > > I would be keen to hear any reasons why this is a bad approach (if it > is, I haven't managed to work this out)? Or perhaps there is a better > one? I'd use a class rather than a dictionary - because with a class, pylint (and perhaps PyChecker and pyflakes?) should be able to detect typos upfront. With a dictionary, typos remain runtime timebombs. From miki.tebeka at gmail.com Fri Feb 11 13:18:48 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 11 Feb 2011 10:18:48 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes In-Reply-To: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> Message-ID: > So speed up the compile-test cycle I'm thinking about running a > completely separate process (not a fork, but a processed launched form > a different terminal) that can load the cache once then dunk it in an > area of shareed memory. Each time I debug the main program, it can > start up quickly and read from the shared memory instead of loading > the cache itself. You can fork and set "hard" breakpoint using "import pdb; pdb.set_trace()". Not sure how Emacs will handle that but you can use pdb from the terminal. For easy forking see http://pythonwise.blogspot.com/2009/04/pmap.html :) Another option to try is maybe mmap the file? HTH, -- Miki http://pythonwise.blogspot.com From andrea.crotti.0 at gmail.com Fri Feb 11 13:23:36 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 11 Feb 2011 19:23:36 +0100 Subject: Class or Dictionary? In-Reply-To: <6be4c7bb-372b-4e75-8b98-7899350d01d5@o18g2000prh.googlegroups.com> References: <084b8a28-ab97-41ff-a88a-92f5c58c89c4@p11g2000vbq.googlegroups.com> <6be4c7bb-372b-4e75-8b98-7899350d01d5@o18g2000prh.googlegroups.com> Message-ID: Il giorno 11/feb/2011, alle ore 17.01, Martin De Kauwe ha scritto: > > i have a number some are smaller, for example switch/control flags. > But the rest can be quite large. I can split them but I don't see the > advantage particularly. Currently by using them (e.g. > params.rate_of_decomp) it clearly distinguishes in the code this was a > model parameter read in from a file. I could create more categories > but it just means more names to remember and change in the code. Well if you read those parameters from a file, I guess it's an INI file. Then if you use configobj you get already a class which can be converted to a dict easily. You can even validate the input to make sure you're not getting out of range values. I always use ini files whenever I can configure something externally, and it works pretty well. Does that help? From tjreedy at udel.edu Fri Feb 11 13:32:29 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 Feb 2011 13:32:29 -0500 Subject: Class or Dictionary? In-Reply-To: References: Message-ID: or Module;-? On 2/11/2011 9:56 AM, Martin De Kauwe wrote: > Hi, > > I have a series of parameter values which i need to pass throughout my > code (>100), in C I would use a structure for example. However in > python it is not clear to me if it would be better to use a dictionary > or build a class object? Personally I think accessing the values is > neater (visually) with an object rather than a dictionary, e.g. Dicts are, of course objects. That said, if all keys are identifier strings, then attribute access is nicer. A module is essentially a dict with all identifier keys, accessed as attributes. mod.a is mod.__dict__['a'] Module are sometimes regarded as singleton data-only classes. Just put 'import params' in every file that needs to read or write them. The stdlib has at least a few modules that consist only of constants. One example is tkinter.constants. -- Terry Jan Reedy From nobody at nowhere.com Fri Feb 11 13:37:16 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 11 Feb 2011 18:37:16 +0000 Subject: Reassign or discard Popen().stdout from a server process References: Message-ID: On Thu, 10 Feb 2011 08:35:24 +0000, John O'Hagan wrote: >> > But I'm still a little curious as to why even unsuccessfully attempting >> > to reassign stdout seems to stop the pipe buffer from filling up. >> >> It doesn't. If the server continues to run, then it's ignoring/handling >> both SIGPIPE and the EPIPE error. Either that, or another process has the >> read end of the pipe open (so no SIGPIPE/EPIPE), and the server is using >> non-blocking I/O or select() so that it doesn't block writing its >> diagnostic messages. > > The server fails with stdout=PIPE if I don't keep reading it, but > doesn't fail if I do stdout=anything (I've tried files, strings, > integers, and None) soon after starting the process, without any other > changes. How is that consistent with either of the above conditions? I'm > sure you're right, I just don't understand. What do you mean by "fail". I wouldn't be surprised if it hung, due to the write() on stdout blocking. If you reassign the .stdout member, the existing file object is likely to become unreferenced, get garbage collected, and close the pipe, which would prevent the server from blocking (the write() will fail rather than blocking). If the server puts the pipe into non-blocking mode, write() will fail with EAGAIN if you don't read it but with EPIPE if you close the pipe. The server may handle these cases differently. From craigyk at scripps.edu Fri Feb 11 13:41:01 2011 From: craigyk at scripps.edu (Craig Yoshida) Date: Fri, 11 Feb 2011 10:41:01 -0800 Subject: Python 32-bit on Windows 64-bit Message-ID: <7AF604E2-FC30-43E0-8D06-5B58F1E7A8DB@scripps.edu> what kind of memory limitations to processes running on 32-bit python (with 32-bit C extensions like scipy) have on 64-bit Windows? I'm having occasional MemoryErrors when running a python program on 64-bit Windows 7 that runs fine on my OS X machine. Both machines are using a 64-bit OS and have 4GB of RAM. Thanks, -Craig From ethan at stoneleaf.us Fri Feb 11 13:47:45 2011 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 11 Feb 2011 10:47:45 -0800 Subject: Class or Dictionary? In-Reply-To: <084b8a28-ab97-41ff-a88a-92f5c58c89c4@p11g2000vbq.googlegroups.com> References: <084b8a28-ab97-41ff-a88a-92f5c58c89c4@p11g2000vbq.googlegroups.com> Message-ID: <4D558451.3030501@stoneleaf.us> Andrea Crotti wrote: > On Feb 11, 3:56 pm, Martin De Kauwe wrote: >> Hi, >> >> I have a series of parameter values which i need to pass throughout my >> code (>100), in C I would use a structure for example. However in >> python it is not clear to me if it would be better to use a dictionary >> or build a class object? Personally I think accessing the values is >> neater (visually) with an object rather than a dictionary, e.g. >> >> x = params['price_of_cats'] * params['price_of_elephants'] >> >> vs. >> >> x = params.price_of_cats * params.price_of_elephants > > Visually neater is not really a good parameter to judge. I strongly disagree. Code readability is one of the most important issues. ~Ethan~ From miki.tebeka at gmail.com Fri Feb 11 13:48:43 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 11 Feb 2011 10:48:43 -0800 (PST) Subject: Class or Dictionary? In-Reply-To: Message-ID: > I have a series of parameter values which i need to pass throughout my > code (>100), in C I would use a structure for example. However in > python it is not clear to me if it would be better to use a dictionary > or build a class object? namedtuple can be a quick and easy solution for you. http://docs.python.org/dev/library/collections.html#collections.namedtuple HTH -- Miki Tebeka http://pythonwise.blogspot.com From Paul.J.Symonds at gmail.com Fri Feb 11 13:50:11 2011 From: Paul.J.Symonds at gmail.com (Paul Symonds) Date: Fri, 11 Feb 2011 18:50:11 +0000 Subject: OO Python References: <4d530c08$0$12170$fa0fcedb@news.zen.co.uk> Message-ID: <4d5584e3$0$12154$fa0fcedb@news.zen.co.uk> Thank you From rdh at new.rr.com Fri Feb 11 14:03:37 2011 From: rdh at new.rr.com (DataSmash) Date: Fri, 11 Feb 2011 11:03:37 -0800 (PST) Subject: Executing functions References: <353073a6-4597-4b32-b8bf-048ef01a5db1@m27g2000prj.googlegroups.com> Message-ID: <1a0da10a-7ea7-4b29-aa13-7ea0d0e74b65@t19g2000prd.googlegroups.com> Appreciate the responses, guys. I now see the difference between the ways I was trying to call function(s). R.D. From enleverLesX_XXmcX at XmclavXeauX.com.invalid Fri Feb 11 14:07:07 2011 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 11 Feb 2011 20:07:07 +0100 Subject: Python 32-bit on Windows 64-bit References: Message-ID: <4d5588e5$0$7710$ba4acef3@reader.news.orange.fr> Hi! Python 32 bits (& Pywin32) limits are: 2 GB on win.7_32 bits 4 GB on win.7_64 bits That's what I found in my tests. @-salutations -- Michel Claveau From doomster at knuut.de Fri Feb 11 14:15:20 2011 From: doomster at knuut.de (Ulrich Eckhardt) Date: Fri, 11 Feb 2011 20:15:20 +0100 Subject: Asterisk sign before the 'self' keyword References: Message-ID: <8rlg69F7hfU1@mid.uni-berlin.de> Hmmm. Is it just us that read this topic and think of an object with a psychic disorder like multiple personalities? :): TGIF. Uli From andrea.crotti.0 at gmail.com Fri Feb 11 14:27:40 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 11 Feb 2011 20:27:40 +0100 Subject: Class or Dictionary? In-Reply-To: <4D558451.3030501@stoneleaf.us> References: <084b8a28-ab97-41ff-a88a-92f5c58c89c4@p11g2000vbq.googlegroups.com> <4D558451.3030501@stoneleaf.us> Message-ID: <9C5EC2F9-F30B-4CFF-A477-E6F61566F007@gmail.com> Il giorno 11/feb/2011, alle ore 19.47, Ethan Furman ha scritto: > > I strongly disagree. Code readability is one of the most important issues. Perfectly agree with that, but obj.name = x obj.surname = y obj['name'] = x obj['surname'] = y are both quite readable in my opinion. Other things are more important to evaluate in this case. I normally always wrap dictionaries because before or later I'll want to add some other features, but I don't know if that's the case here. From jeanmichel at sequans.com Fri Feb 11 15:01:48 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 11 Feb 2011 21:01:48 +0100 Subject: Class or Dictionary? In-Reply-To: References: Message-ID: <4D5595AC.2090308@sequans.com> Martin De Kauwe wrote: > Hi, > > I have a series of parameter values which i need to pass throughout my > code (>100), in C I would use a structure for example. However in > python it is not clear to me if it would be better to use a dictionary > or build a class object? Personally I think accessing the values is > neater (visually) with an object rather than a dictionary, e.g. > > x = params['price_of_cats'] * params['price_of_elephants'] > > vs. > > x = params.price_of_cats * params.price_of_elephants > > So currently I am building a series of class objects to hold different > parameters and then passing these through my code, e.g. > > class EmptyObject: > pass > > self.animal_prices = EmptyObject() > self.price_of_cats = 12 or reading a file and populating the object > > > I would be keen to hear any reasons why this is a bad approach (if it > is, I haven't managed to work this out)? Or perhaps there is a better > one? > > thanks > > Martin > Using classes is the best choice. However, if because there would be too much classes to define so that you are forced to use your EmptyObject trick, adding attributes to the inntance dynamically, I'd say that dictionnaries are a more common pattern. Ideally, you would have something like: class PriceHolder(object): @classmethod def fromFile(cls, filename): # example of abstract method pass class Animals(PriceHolder): def __init__(self): self.cat = None self.elephant = None class Fruits(PriceHolder): def __init__(self): self.banana = None self.apple = None Then you would have to write 100 PriceHolder subclasses... JM From wdepli at mikrotec.com Fri Feb 11 15:10:45 2011 From: wdepli at mikrotec.com (Doug Epling) Date: Fri, 11 Feb 2011 15:10:45 -0500 Subject: Another related OO Python ? Message-ID: hey, does anyone find the UML useful during Python development of larger projects? From martin at v.loewis.de Fri Feb 11 15:54:25 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 11 Feb 2011 21:54:25 +0100 Subject: Python 32-bit on Windows 64-bit In-Reply-To: References: Message-ID: <4D55A201.9060302@v.loewis.de> Am 11.02.2011 19:41, schrieb Craig Yoshida: > what kind of memory limitations to processes running on 32-bit python > (with 32-bit C extensions like scipy) have on 64-bit Windows? I'm > having occasional MemoryErrors when running a python program on > 64-bit Windows 7 that runs fine on my OS X machine. Both machines > are using a 64-bit OS and have 4GB of RAM. In addition to the limitations Michel reports: on a 32-bit system, objects are typically limited to using at most 2GiB, per object (of course, you could have at most two objects that come close to this size, since the whole address space would not be larger than 4GiB). Regards, Martin From martin at v.loewis.de Fri Feb 11 15:54:25 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 11 Feb 2011 21:54:25 +0100 Subject: Python 32-bit on Windows 64-bit In-Reply-To: References: Message-ID: <4D55A201.9060302@v.loewis.de> Am 11.02.2011 19:41, schrieb Craig Yoshida: > what kind of memory limitations to processes running on 32-bit python > (with 32-bit C extensions like scipy) have on 64-bit Windows? I'm > having occasional MemoryErrors when running a python program on > 64-bit Windows 7 that runs fine on my OS X machine. Both machines > are using a 64-bit OS and have 4GB of RAM. In addition to the limitations Michel reports: on a 32-bit system, objects are typically limited to using at most 2GiB, per object (of course, you could have at most two objects that come close to this size, since the whole address space would not be larger than 4GiB). Regards, Martin From ll.snark at gmail.com Fri Feb 11 16:24:15 2011 From: ll.snark at gmail.com (LL.Snark) Date: Fri, 11 Feb 2011 22:24:15 +0100 Subject: Arrays/List, filters, Pytho, Ruby Message-ID: <4d55a9b5$0$19686$426a34cc@news.free.fr> Hi, I'm looking for a pythonic way to translate this short Ruby code : t=[6,7,8,6,7,9,8,4,3,6,7] i=t.index {|x| x=t[0] : i+=1 ... not pythonic I think... Or : t=[6,7,8,6,7,9,8,4,3,6,7] i=[j for j in range(len(t)) if t[j] Message-ID: <49fe3a8d-d251-499c-bdaf-dcabe76f0a93@glegroupsg2000goo.googlegroups.com> On Friday, February 11, 2011 5:24:15 PM UTC-4, LL.Snark wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it in python several ways : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=0 > while t[i]>=t[0] : i+=1 > > ... not pythonic I think... > > Or : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=[j for j in range(len(t)) if t[j] > ...too cryptic... > You could go with something like (untested) t = [6,7,8,6,7,9,8,4,3,6,7] for i, j in enumerate(t): if j < t[0]: break else: i = 0 ;-) > I'm using Python 3. > > Thx From clp2 at rebertia.com Fri Feb 11 16:44:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 11 Feb 2011 13:44:26 -0800 Subject: Arrays/List, filters, Pytho, Ruby In-Reply-To: <4d55a9b5$0$19686$426a34cc@news.free.fr> References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: On Fri, Feb 11, 2011 at 1:24 PM, LL.Snark wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it in python several ways : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=0 > while t[i]>=t[0] : i+=1 > > ... not pythonic I think... > > Or : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=[j for j in range(len(t)) if t[j] > ...too cryptic... > > I'm using Python 3. My version: t = [6,7,8,6,7,9,8,4,3,6,7] i = -1 for index, item in enumerate(t): if item < t[0]: i = index break I'm a big fan of enumerate(). I'm sure an itertools solution is also possible. Cheers, Chris -- http://blog.rebertia.com From sherm.pendley at gmail.com Fri Feb 11 16:50:23 2011 From: sherm.pendley at gmail.com (Sherm Pendley) Date: Fri, 11 Feb 2011 16:50:23 -0500 Subject: Python 32-bit on Windows 64-bit References: <4D55A201.9060302@v.loewis.de> Message-ID: "Martin v. Loewis" writes: > Am 11.02.2011 19:41, schrieb Craig Yoshida: >> what kind of memory limitations to processes running on 32-bit python >> (with 32-bit C extensions like scipy) have on 64-bit Windows? I'm >> having occasional MemoryErrors when running a python program on >> 64-bit Windows 7 that runs fine on my OS X machine. Both machines >> are using a 64-bit OS and have 4GB of RAM. > > In addition to the limitations Michel reports: on a 32-bit system, > objects are typically limited to using at most 2GiB, per object > (of course, you could have at most two objects that come close to > this size, since the whole address space would not be larger than > 4GiB). IIRC, 32-bit Windows programs are limited to 2GiB, reserving the rest of the virtual address space for Windows' own use. Also, 32-bit apps remain 32-bit, even if they're running on a 64-bit capable OS. Assuming you're running Snow Leopard on your Mac, you're using a 64-bit Python interpreter *and* a 64-bit OS. You need to have both to take advantage of a 64-bit memory space. sherm-- -- Sherm Pendley Cocoa Developer From drsalists at gmail.com Fri Feb 11 16:51:31 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 11 Feb 2011 13:51:31 -0800 Subject: Arrays/List, filters, Pytho, Ruby In-Reply-To: <49fe3a8d-d251-499c-bdaf-dcabe76f0a93@glegroupsg2000goo.googlegroups.com> References: <4d55a9b5$0$19686$426a34cc@news.free.fr> <49fe3a8d-d251-499c-bdaf-dcabe76f0a93@glegroupsg2000goo.googlegroups.com> Message-ID: On Fri, Feb 11, 2011 at 1:43 PM, Andr? Roberge wrote: > On Friday, February 11, 2011 5:24:15 PM UTC-4, LL.Snark wrote: >> Hi, >> >> I'm looking for a pythonic way to translate this short Ruby code : >> t=[6,7,8,6,7,9,8,4,3,6,7] >> i=t.index {|x| x> >> If you don't know Ruby, the second line means : >> What is the index, in array t, of the first element x such that x> >> If can write it in python several ways : >> t=[6,7,8,6,7,9,8,4,3,6,7] >> i=0 >> while t[i]>=t[0] : i+=1 >> >> ... not pythonic I think... >> >> Or : >> t=[6,7,8,6,7,9,8,4,3,6,7] >> i=[j for j in range(len(t)) if t[j]> >> ...too cryptic... >> > You could go with something like (untested) > t = [6,7,8,6,7,9,8,4,3,6,7] > for i, j in enumerate(t): > ? ?if j < t[0]: > ? ? ? ?break > else: > ? ? ? ?i = 0 > > ;-) > > > >> I'm using Python 3. >> >> Thx >>> t = [6,7,8,6,7,9,8,4,3,6,7] >>> generator = (element for element in t[1:] if element >= t[0]) >>> print(next(generator)) From ian.g.kelly at gmail.com Fri Feb 11 17:04:45 2011 From: ian.g.kelly at gmail.com (Ian) Date: Fri, 11 Feb 2011 14:04:45 -0800 (PST) Subject: Arrays/List, filters, Pytho, Ruby References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <972c2596-d1fc-47b2-a958-3afbfb87e68f@o32g2000prb.googlegroups.com> On Feb 11, 2:24?pm, "LL.Snark" wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x References: <4d55a9b5$0$19686$426a34cc@news.free.fr> <49fe3a8d-d251-499c-bdaf-dcabe76f0a93@glegroupsg2000goo.googlegroups.com> Message-ID: On Fri, Feb 11, 2011 at 1:51 PM, Dan Stromberg wrote: > On Fri, Feb 11, 2011 at 1:43 PM, Andr? Roberge > wrote: > > On Friday, February 11, 2011 5:24:15 PM UTC-4, LL.Snark wrote: > >> Hi, > >> > >> I'm looking for a pythonic way to translate this short Ruby code : > >> t=[6,7,8,6,7,9,8,4,3,6,7] > >> i=t.index {|x| x >> > >> If you don't know Ruby, the second line means : > >> What is the index, in array t, of the first element x such that x >> > >> If can write it in python several ways : > >> t=[6,7,8,6,7,9,8,4,3,6,7] > >> i=0 > >> while t[i]>=t[0] : i+=1 > >> > >> ... not pythonic I think... > >> > >> Or : > >> t=[6,7,8,6,7,9,8,4,3,6,7] > >> i=[j for j in range(len(t)) if t[j] >> > >> ...too cryptic... > >> > > You could go with something like (untested) > > t = [6,7,8,6,7,9,8,4,3,6,7] > > for i, j in enumerate(t): > > if j < t[0]: > > break > > else: > > i = 0 > > > > ;-) > > > > > > > >> I'm using Python 3. > >> > >> Thx > > >>> t = [6,7,8,6,7,9,8,4,3,6,7] > >>> generator = (element for element in t[1:] if element >= t[0]) > >>> print(next(generator)) > -- > http://mail.python.org/mailman/listinfo/python-list > Since we only care about the 1st generated value ... t = [6,7,8,6,7,9,8,4,3,6,7] t.index(next((elem for elem in t[1:] if elem < t[0]))) -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Feb 11 17:38:51 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 11 Feb 2011 14:38:51 -0800 Subject: Arrays/List, filters, Pytho, Ruby In-Reply-To: References: <4d55a9b5$0$19686$426a34cc@news.free.fr> <49fe3a8d-d251-499c-bdaf-dcabe76f0a93@glegroupsg2000goo.googlegroups.com> Message-ID: On Fri, Feb 11, 2011 at 1:51 PM, Dan Stromberg wrote: > On Fri, Feb 11, 2011 at 1:43 PM, Andr? Roberge wrote: >> On Friday, February 11, 2011 5:24:15 PM UTC-4, LL.Snark wrote: >>> Hi, >>> >>> I'm looking for a pythonic way to translate this short Ruby code : >>> t=[6,7,8,6,7,9,8,4,3,6,7] >>> i=t.index {|x| x>> >>> If you don't know Ruby, the second line means : >>> What is the index, in array t, of the first element x such that x>> >>> If can write it in python several ways : >>> t=[6,7,8,6,7,9,8,4,3,6,7] >>> i=0 >>> while t[i]>=t[0] : i+=1 >>> >>> ... not pythonic I think... >>> >>> Or : >>> t=[6,7,8,6,7,9,8,4,3,6,7] >>> i=[j for j in range(len(t)) if t[j]>> >>> ...too cryptic... >>> >> You could go with something like (untested) >> t = [6,7,8,6,7,9,8,4,3,6,7] >> for i, j in enumerate(t): >> ? ?if j < t[0]: >> ? ? ? ?break >> else: >> ? ? ? ?i = 0 >> >> ;-) >> >> >> >>> I'm using Python 3. >>> >>> Thx > >>>> t = [6,7,8,6,7,9,8,4,3,6,7] >>>> generator = (element for element in t[1:] if element >= t[0]) >>>> print(next(generator)) > Oops; a correction. Fast and concise - and if you decide you need the 2nd or 10th, they'll be on their way as soon as you request them (lazy evaluation): >>> generator = (ind+1 for ind, element in enumerate(t[1:]) if element >= t[0]) >>> print(next(generator)) From no.email at nospam.invalid Fri Feb 11 17:46:33 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 11 Feb 2011 14:46:33 -0800 Subject: Arrays/List, filters, Pytho, Ruby References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <7xwrl62nqu.fsf@ruckus.brouhaha.com> "LL.Snark" writes: > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x=t[0], t).next() Note the above can throw an exception if no suitable element is found. t=[6,7,8,6,7,9,8,4,3,6,7] i=[j for j in range(len(t)) if t[j] Message-ID: <4d55bcde$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Feb 2011 07:06:11 -0800, christian.posta wrote: > Within the __call__ function for a class, I saw a method of that class > referred to like this: > > *self.() > > The brackets indicate the method name. What does the *self refer to?? > Does it somehow indicate the scope of the 'self' variable? Thanks in > advance... self is not a keyworld. It is an ordinary variable name like any other, except that by convention it is used to refer to the instance inside methods. Without knowing the context, *self.method() could mean at least one of two things: (1) Ordinary multiplication: result = 42*self.method() This is like: temp = self.method() result = 42*temp (2) Positional argument unpacking: result = function(*self.method()) This is like: temp = self.method() result = function(temp[0], temp[1], temp[2], ...) or if you prefer, like the old and now deprecated function: result = apply(function, temp) -- Steven From bswolf at google.com Fri Feb 11 18:10:52 2011 From: bswolf at google.com (Benjamin S Wolf) Date: Fri, 11 Feb 2011 15:10:52 -0800 (PST) Subject: For loop comprehensions Message-ID: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> It occurred to me as I was writing a for loop that I would like to write it in generator comprehension syntax, eg. for a in b if c: rather than using one of the more verbose but allowable syntaxes: for a in (x for x in b if c): for a in b: if not c: continue Python 3.1 does not support "for comprehensions", and a few cursory searches of PEPs and this list don't turn up anything. I like the idea enough to suggest it though I'm unfamiliar with the PEP/feature request process (PEP 1 pointed me here). What do other people think? --Ben From joncle at googlemail.com Fri Feb 11 18:27:31 2011 From: joncle at googlemail.com (Jon Clements) Date: Fri, 11 Feb 2011 15:27:31 -0800 (PST) Subject: Arrays/List, filters, Pytho, Ruby References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <5a0e4846-f04f-4fae-951c-4c581ebf759d@r13g2000yqk.googlegroups.com> On Feb 11, 9:24?pm, "LL.Snark" wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it in python several ways : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=0 > while t[i]>=t[0] : i+=1 > > ... not pythonic I think... > > Or : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=[j for j in range(len(t)) if t[j] > ...too cryptic... > > I'm using Python 3. > > Thx My take (but using Python 2.x): import operator as op from functools import partial from itertools import islice t = [6,7,8,6,7,9,8,4,3,6,7] def first_conditional(seq, first=op.itemgetter(0), pred=op.gt): f = first(seq) cmpfunc = partial(pred, f) for idx, val in enumerate(islice(seq, 1, None)): if cmpfunc(val): return idx + 1 return -1 # or raise an exception? Off top of head, so needs work, but is fairly generic. Jon. From joncle at googlemail.com Fri Feb 11 18:44:01 2011 From: joncle at googlemail.com (Jon Clements) Date: Fri, 11 Feb 2011 15:44:01 -0800 (PST) Subject: For loop comprehensions References: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> Message-ID: <7ec375d9-b664-48eb-a288-bd90856bbd8f@n1g2000yqm.googlegroups.com> On Feb 11, 11:10?pm, Benjamin S Wolf wrote: > It occurred to me as I was writing a for loop that I would like to > write it in generator comprehension syntax, eg. > > ? for a in b if c: > > rather than using one of the more verbose but allowable syntaxes: > > ? for a in (x for x in b if c): > > ? for a in b: > ? ? if not c: continue > > Python 3.1 does not support "for comprehensions", and a few cursory > searches of PEPs and this list don't turn up anything. I like the idea > enough to suggest it though I'm unfamiliar with the PEP/feature > request process (PEP 1 pointed me here). What do other people think? > > --Ben Can't help with the PEP stuff, but ummm... is anything wrong with filter()? For some things, I personally find it more readable in some circumstances than list/gen comps. I don't mind predicates at "the end", but sometimes they're more obvious at "the front". Jon. From mdekauwe at gmail.com Fri Feb 11 18:45:16 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 11 Feb 2011 15:45:16 -0800 (PST) Subject: Class or Dictionary? References: Message-ID: <3d711f8b-8651-4add-84a6-c66a0a1dd64a@o32g2000prb.googlegroups.com> Hi, yes I read a .INI file using ConfigParser, just similar sections (in my opinion) to make one object which i can then pass to different classes. E.G. class Dict2Obj: """ Turn a dictionary into an object. The only purpose of this is that I think it is neater to reference values x.soiltemp rather than x['soiltemp'] ;P """ def __init__(self, dict): for k, v in dict.items(): setattr(self, k, v) class Parser(object): """ Load up all the initialisation data. Return the met data as an array, perhaps we should really also return a header as well? Return the ini file as various objects. """ def __init__(self, ini_fname, met_fname): self.ini_fname = ini_fname self.met_fname = met_fname def load_files(self): # read the driving data in, this may get more complicated? met_data = met_data = np.loadtxt(self.met_fname, comments='#') # read the configuration file into a different dicts, break up # into model_params, control and state config = ConfigParser.RawConfigParser() config.read(self.ini_fname) # params model_params = {} sections = ['water','nitra','soilp','carba','litter','envir','prodn'] for section in sections: for option in config.options(section): model_params[option] = config.getfloat(section, option) # turn dict into an object model_params = Dict2Obj(model_params) # control control = {} for option in config.options('control'): control[option] = config.getint('control', option) # turn dict into an object control = Dict2Obj(control) initial_state = {} sections = ['cinit','ninit','vinit'] for section in sections: for option in config.options(section): initial_state[option] = config.getfloat(section, option) # turn dict into objects initial_state = Dict2Obj(initial_state) return (initial_state, control, model_params, met_data) So I would then pass these objects through my code, for example a given class would just expect to inherit params perhaps. class calc_weight(object): def __init__(self, params): self.params = params There are also "states" that evolve through the code which various methods of a given class change. For example lets call it elephants weight. So the model will do various things to predict changes in our elephants weight, so there will be a class to calculate his/her food intake etc. Using this example the other thing I wanted to do was pass "states" around like self.elephant_weight. However it occurred to me if I just used self.elephant_weight for example it would make it harder to call individual components seperately, so better to stick to the same method and using an object i reasoned. Hence I started with my emptydict thing, I hope that helps make it clearer? class EmptyObject: pass # generate some objects to store pools and fluxes... self.pools = EmptyObject() # add stuff to it self.pools.elephant_weight = 12.0 thanks for all of the suggestions it is very insightful From anikom15 at gmail.com Fri Feb 11 18:47:08 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 11 Feb 2011 15:47:08 -0800 Subject: For loop comprehensions In-Reply-To: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> References: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> Message-ID: <1297468028.2517.3.camel@localhost.localdomain> On Fri, 2011-02-11 at 15:10 -0800, Benjamin S Wolf wrote: > It occurred to me as I was writing a for loop that I would like to > write it in generator comprehension syntax, eg. > > for a in b if c: > > rather than using one of the more verbose but allowable syntaxes: > > for a in (x for x in b if c): > > for a in b: > if not c: continue > > Python 3.1 does not support "for comprehensions", and a few cursory > searches of PEPs and this list don't turn up anything. I like the idea > enough to suggest it though I'm unfamiliar with the PEP/feature > request process (PEP 1 pointed me here). What do other people think? > > --Ben No, too confusing. Then people'll want compound loops e.g.: for a in b if c while d else return x: print('Ha ha I'm so clever!') From ian.g.kelly at gmail.com Fri Feb 11 18:59:52 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Feb 2011 16:59:52 -0700 Subject: For loop comprehensions In-Reply-To: <1297468028.2517.3.camel@localhost.localdomain> References: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> <1297468028.2517.3.camel@localhost.localdomain> Message-ID: On Fri, Feb 11, 2011 at 4:47 PM, Westley Mart?nez wrote: > No, too confusing. Then people'll want compound loops e.g.: > > for a in b if c while d else return x: > ? ?print('Ha ha I'm so clever!') I've yet to see anybody arguing for while loops to be nested like that, but we already allow nested for loops in comprehensions and generator expressions: [(x, y) for x in a for y in b if c(y)] Why not allow the same thing in for-loop conditions? I think that anything that makes the language syntax more consistent is good. Cheers, Ian From ll.snark at gmail.com Fri Feb 11 19:11:31 2011 From: ll.snark at gmail.com (LL.Snark) Date: Sat, 12 Feb 2011 01:11:31 +0100 Subject: Arrays/List, filters, Pytho, Ruby In-Reply-To: <4d55a9b5$0$19686$426a34cc@news.free.fr> References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <4d55d0ea$0$18752$426a74cc@news.free.fr> On 11/02/2011 22:24, LL.Snark wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it in python several ways : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=0 > while t[i]>=t[0] : i+=1 > > ... not pythonic I think... > > Or : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=[j for j in range(len(t)) if t[j] > ...too cryptic... > > I'm using Python 3. Thx for your answers. May I add some comments ? ===================================================== t = [6,7,8,6,7,9,8,4,3,6,7] i = -1 for index, item in enumerate(t): if item < t[0]: i = index break is OK for me, while a bit too long :) ====================================================== from itertools import dropwhile t=[6,7,8,6,7,9,8,4,3,6,7] i = dropwhile(lambda k: t[k]>=t[0], t).__next__() (I added the __ around next. Am i true ?) This does not work for me. i is effectively 7, but 7 is the second item of the array. If you try : t=[6,8,8,6,7,9,8,4,3,6,7] i = dropwhile(lambda k: t[k]>=t[0], t).__next__() You will get 8. I guess this is because k is a value of the array, not an index. In the first example, we compare t[6], then t[7], then t[8], t[6], t[7] etc... to t[0]. (It happens that the first item of the list is dropped... then the first element of the resulting list is 7... the answer... but it was just luck) ===================================================== The javalicious one : class ComparisonPredicate: def __init__(self, func): self.func = func def __eq__(self, other): return self.func(other) t = [6, 7, 8, 6, 7, 9, 8, 4, 3, 6, 7] print(t.index(ComparisonPredicate(lambda x: x < t[0]))) It took me some time to understand :) It's a shame there is no built-in object like ComparisonPredicate, because the line t.index(ComparisonPredicate(lambda x: x < t[0])) looks good to me. =================================================== Finally, the other enumerate solution may be written like this : t = [6,7,8,6,7,9,8,4,3,6,7] for i, j in enumerate(t): if j < t[0]: break else : i=-1 Quite short. ================================================= Finally, with your solutions, I build another one. Here it is : t=[6,7,8,6,7,9,8,4,3,6,7] i,j=filter(lambda x: x[1]=t[0],enumerate(t)).__next__() Or else : t=[6,7,8,6,7,9,8,4,3,6,7] t.index(filter(lambda x: x Message-ID: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Feb 2011 10:15:27 -0800, Dan Stromberg wrote: > I'd use a class rather than a dictionary - because with a class, pylint > (and perhaps PyChecker and pyflakes?) should be able to detect typos > upfront. *Some* typos. Certainly not all. The more complex the code -- and with 100 or so parameters, this sounds pretty damn complex -- there is a non-negligible risk of mistakenly using the wrong name. Unless pylint now has a "do what I mean, not what I say" mode, it can't save you from typos like this: params.employerID = 23 params.employeeID = 42 # much later if params.employeeID == 23: # Oops, I meant employ*er*ID ... > With a dictionary, typos remain runtime timebombs. Are your unit tests broken? You should fix that and not rely on just pylint to detect bugs. Unit tests will help protect you against many more bugs than just typos. Besides, and I quote... "I find it amusing when novice programmers believe their main job is preventing programs from crashing. ... More experienced programmers realize that correct code is great, code that crashes could use improvement, but incorrect code that doesn't crash is a horrible nightmare." -- Chris Smith -- Steven From mdekauwe at gmail.com Fri Feb 11 19:24:26 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 11 Feb 2011 16:24:26 -0800 (PST) Subject: Class or Dictionary? References: <3d711f8b-8651-4add-84a6-c66a0a1dd64a@o32g2000prb.googlegroups.com> Message-ID: <508804b1-fa3e-4bf1-827f-c1617c6f9750@r19g2000prm.googlegroups.com> Sorry I should have added a little more example to help with clarity? So after reading the .INI file I then initialise the objects I described e.g. def initialise_simulation(self): """Set the initial conditions. using values from the .ini value set the C and N pools and other misc states. """ for attr, value in self.initial_state.__dict__.iteritems(): #print attr, value setattr(self.pools, attr, value) # maybe need M2_AS_HA here? self.pools.lai = self.params.sla * self.params.cfrac_dry_mass self.fluxes.nuptake = 0.0 From python at mrabarnett.plus.com Fri Feb 11 19:27:36 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Feb 2011 00:27:36 +0000 Subject: Python 32-bit on Windows 64-bit In-Reply-To: References: <4D55A201.9060302@v.loewis.de> Message-ID: <4D55D3F8.5010302@mrabarnett.plus.com> On 11/02/2011 21:50, Sherm Pendley wrote: > "Martin v. Loewis" writes: > >> Am 11.02.2011 19:41, schrieb Craig Yoshida: >>> what kind of memory limitations to processes running on 32-bit python >>> (with 32-bit C extensions like scipy) have on 64-bit Windows? I'm >>> having occasional MemoryErrors when running a python program on >>> 64-bit Windows 7 that runs fine on my OS X machine. Both machines >>> are using a 64-bit OS and have 4GB of RAM. >> >> In addition to the limitations Michel reports: on a 32-bit system, >> objects are typically limited to using at most 2GiB, per object >> (of course, you could have at most two objects that come close to >> this size, since the whole address space would not be larger than >> 4GiB). > > IIRC, 32-bit Windows programs are limited to 2GiB, reserving the rest > of the virtual address space for Windows' own use. > It's possible to configure 32-bit Windows to allow up to 3GB user RAM. > Also, 32-bit apps remain 32-bit, even if they're running on a 64-bit > capable OS. Assuming you're running Snow Leopard on your Mac, you're > using a 64-bit Python interpreter *and* a 64-bit OS. You need to have > both to take advantage of a 64-bit memory space. > From mdekauwe at gmail.com Fri Feb 11 19:31:09 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 11 Feb 2011 16:31:09 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> On Feb 12, 11:13?am, Steven D'Aprano wrote: > On Fri, 11 Feb 2011 10:15:27 -0800, Dan Stromberg wrote: > > I'd use a class rather than a dictionary - because with a class, pylint > > (and perhaps PyChecker and pyflakes?) should be able to detect typos > > upfront. ? > > *Some* typos. Certainly not all. > > The more complex the code -- and with 100 or so parameters, this sounds > pretty damn complex -- there is a non-negligible risk of mistakenly using > the wrong name. Unless pylint now has a "do what I mean, not what I say" > mode, it can't save you from typos like this: > > params.employerID = 23 > params.employeeID = 42 > # much later > if params.employeeID == 23: > ? ? # Oops, I meant employ*er*ID > ? ? ... > > > With a dictionary, typos remain runtime timebombs. > > Are your unit tests broken? You should fix that and not rely on just > pylint to detect bugs. Unit tests will help protect you against many more > bugs than just typos. > > Besides, and I quote... > > "I find it amusing when novice programmers believe their main job is > preventing programs from crashing. ... More experienced programmers > realize that correct code is great, code that crashes could use > improvement, but incorrect code that doesn't crash is a horrible > nightmare." -- Chris Smith > > -- > Steven The 100+ parameters just means "everything" can be adjusted outside of the code, invariable most of it isn't. I am setting this up with some bayesian calibration in mind. A lot of those parameters will be switches as well. I think perhaps I will write a defaults module and just read a .INI file with the values the user wants changing. Originally I was just going to read everything in, but maybe this is better from a usage point of view. As I said I am happy to consider a dictionary, although some of the calculations are quite complex and I *think* it is easier to read this way, rather than with a dictionary. That is purely an opinion, I don't have a computer science background and so I am asking really, is what I am doing very bad, and if so why? What do other people do? I have tried to search a lot on this subject but I find the example not very specific, (or I am reading the wrong places). thanks. From steve+comp.lang.python at pearwood.info Fri Feb 11 21:11:49 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Feb 2011 02:11:49 GMT Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> Message-ID: <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Feb 2011 16:31:09 -0800, Martin De Kauwe wrote: > The 100+ parameters just means "everything" can be adjusted outside of > the code, invariable most of it isn't. If people aren't going to change all these parameters, why are you spending the time and energy writing code for something that won't happen? There are *real costs* to increasing the amount of customization people can do with your code. The more complex your code, the more bugs it will contain. You should consider this almost a law of nature. The more power you give people to change parameters, the more often they will hit unexpected interactions between parameters that you never imagined. You should expect bug reports that will take forever to track down, because (for example) the bug only occurs when param #37 is larger than param #45, but only if param #62 is less than param #5 and both are less than 100 and param #83 is a multiple of 17... The more complex your code, the more tests you will need to be sure the code does what you expect. The number of combinations that need testing *explodes* exponentially. You simply cannot test every combination of parameters. Untested code should be considered buggy until proven otherwise. Think very carefully before allowing over-customization. Take into account the costs as well as the benefits. Then, if you still decide to allow all that customization, at least you know that the pain will be worth it. > As I said I am happy to consider a dictionary, although some of the > calculations are quite complex and I *think* it is easier to read this > way, rather than with a dictionary. I believe that most of these calculations should be written as functions which take arguments. This will allow better testing and customization. Instead of writing complex calculations inline, you should make them functions or methods. There's little difference in complexity between: my_calculation(arg1, arg2, arg3, params.x, params.y, params.z) and my_calculation(arg1, arg2, arg3, params['x'], params['y'], params['z']) (although, as you have realised, the second is a little more visually noisy -- but not that much). Better still, have the function use sensible default values: def my_calculation(arg1, arg2, arg3, x=None, y=None, z=None): if x is None: x = params.x # or params['x'], who cares? if y is None: y = params['y'] # or params.x ... This gives you the best of both worlds: you can supply parameters at runtime, for testing or customization, but if you don't, the function will use sensible defaults. > That is purely an opinion, I don't > have a computer science background and so I am asking really, is what I > am doing very bad, and if so why? What do other people do? I have tried > to search a lot on this subject but I find the example not very > specific, (or I am reading the wrong places). Whether you use obj.x or obj['x'] is the least important part of the problem. That's merely syntax. -- Steven From steve+comp.lang.python at pearwood.info Fri Feb 11 21:34:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Feb 2011 02:34:02 GMT Subject: For loop comprehensions References: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> <1297468028.2517.3.camel@localhost.localdomain> Message-ID: <4d55f199$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Feb 2011 16:59:52 -0700, Ian Kelly wrote: > Why not allow the same thing in for-loop conditions? Because new syntax and new language features means more work. Somebody has to write the code, make sure that it doesn't break existing Python code, test it for bugs, change the documentation, write regression tests for it... And then, having done it for CPython, somebody else has to do the same for IronPython, Jython, PyPy, CLPython, Stackless ... And all that code has to be maintained. Because new syntax and features increases the size and complexity of the Python code base, which means more bugs and more tests needed. Because new syntax and features increases the size and complexity of the documentation needed, and hence increases the amount of things that need to be learned. Because the guiding philosophy of Python is "there should be one, and preferably only one, obvious way to do it". That doesn't mean that multiple ways of doing it are forbidden (far from it!) but it does mean that Python is conservative about adding multiple ways of spelling the same thing. New features don't come for free. They have costs too. You need something more than just "why not" to justify adding features -- you also need a "why" as well. So... why add extra syntax to for loops when they're already very simple and effective? There's nothing wrong with writing for x in iterable: if condition(x): process(x) The existing syntax is clear and obvious. There's no clear benefit to shifting the if clause to the for expression: it complicates the parser, and any benefit (if any!) only applies to a tiny fraction of for loops. You save one line, which is trivial. You may save one indentation level, which might, sometimes, be useful, but more often will also be trivial. If there's an advantage to the suggestion, it's small. > I think that > anything that makes the language syntax more consistent is good. "A foolish consistency is the hobgoblin of little minds." Consistency, in and of itself, is not a virtue. -- Steven From steve+comp.lang.python at pearwood.info Fri Feb 11 21:35:56 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Feb 2011 02:35:56 GMT Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d55f20c$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Feb 2011 01:29:02 -0500, Chris Jones wrote: >> >> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' [...] > First of all, you need to know precisely what the above font name coding > means. [...] > http://www.archive.org/details/xwindowsytemosf03querarch Thanks for the link, that's incredibly useful (although the PDF doesn't render correctly in any of the five different PDF viewers I tried, but I was able to read it). -- Steven From yanghq at neusoft.com Fri Feb 11 22:01:10 2011 From: yanghq at neusoft.com (yanghq) Date: Sat, 12 Feb 2011 11:01:10 +0800 Subject: parse html rendered by js In-Reply-To: References: Message-ID: <1297479670.2144.9.camel@ocean-desktop> thank u for your reply. yeah, my end goal is something like screen scraping a web site. Duplicating the Javascript behaviour in my Python code will be a huge burden,I'm afraid time can't aford it. someone say that webkit / pamie and other browser engine can render js to html,but pamie is only work for windows, and webkit is hard to retrieve for me.I am searching other browser engine. On Fri, 2011-02-11 at 06:46 -0800, Alex Willmer wrote: > On Feb 11, 8:20 am, yanghq wrote: > > hi, > > I wanna get attribute value like href,src... in html. > > > > for simple html page libxml2dom can help me parse it into dom, and > > get what I want; > > > > but for some pages rendered by js, like: > > > > document.write( > > ' > onUnload="end()" onResize="change()">'+ > > ''+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > ... > > ) > > how can I get the atrribute value of 'src', thank you for any help. > > You can > - Duplicate the Javascript behaviour in your Python code (i.e. rewrite > it yourself). Whenever the javascript changes you will need to update > your duplicate code. > - Use or write a Python module that uses a web browser to download/ > execute the page. I'm not aware of any that exist. > > Neither option is very good, and that is one reason why such > Javascript is considered bad practise. What is your end goal - e.g. > testing a web application, screen scraping a web site)? There may be a > better way. > > Alex --------------------------------------------------------------------------------------------------- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. --------------------------------------------------------------------------------------------------- From stirredo at gmail.com Fri Feb 11 22:20:26 2011 From: stirredo at gmail.com (Abhishek Gulyani) Date: Sat, 12 Feb 2011 08:50:26 +0530 Subject: Writing binary files in windows Message-ID: When I write binary files in windows: file = open(r'D:\Data.bin','wb') file.write('Random text') file.close() and then open the file it just shows up as normal text. There is nothing binary about it. Why is that? Sorry if this is too much of a noobie question. I tried googling around but couldn't find an answer. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kb1pkl at aim.com Fri Feb 11 22:35:23 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Fri, 11 Feb 2011 22:35:23 -0500 Subject: Writing binary files in windows In-Reply-To: References: Message-ID: <4D55FFFB.1080207@aim.com> On 02/11/2011 10:20 PM, Abhishek Gulyani wrote: > When I write binary files in windows: > > file = open(r'D:\Data.bin','wb') > file.write('Random text') > file.close() > > and then open the file it just shows up as normal text. There is nothing > binary about it. Why is that? > > Sorry if this is too much of a noobie question. I tried googling around but > couldn't find an answer. > It is binary! What are you expecting? You wrote text to a file, so when you open the file with whatever, it displays like text. Even when you don't open a file as binary, it is still a binary file. Otherwise it wouldn't exist. From airscorp at otenet.gr Fri Feb 11 22:38:02 2011 From: airscorp at otenet.gr (Nick Raptis) Date: Sat, 12 Feb 2011 05:38:02 +0200 Subject: Writing binary files in windows In-Reply-To: References: Message-ID: <4D56009A.6070005@otenet.gr> On 02/12/2011 05:20 AM, Abhishek Gulyani wrote: > When I write binary files in windows: > > file = open(r'D:\Data.bin','wb') > file.write('Random text') > file.close() > > and then open the file it just shows up as normal text. There is > nothing binary about it. Why is that? > > Sorry if this is too much of a noobie question. I tried googling > around but couldn't find an answer. > But then, you opened the file you created in Notepad and saw that the lines weren't wrapping maybe? It all comes down to Line endings. Read here to see what LF vs. CRLF is all about http://en.wikipedia.org/wiki/Newline#Representations You see, when you read a file, Python converts both LF and CRLF to "\n". When you write a "\n" to a file Python writes CRLF in Windows and just LF in Unix machines. That'd be a heck troublesome when dealing with binary files, hence the 'b' flag. It basically means *Don't convert newlines", and it's pretty common in software. So, to answer your question: If you're only writing text to a file, you'll only see a difference if your external text editor isn't smart enough to treat both LF and CRLF as newlines. Like Notepad did back in the day, and maybe still does. But if you're writing binary stuff, it makes all the difference in the world. Nick From tjreedy at udel.edu Fri Feb 11 22:49:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 11 Feb 2011 22:49:11 -0500 Subject: Arrays/List, filters, Pytho, Ruby In-Reply-To: <4d55a9b5$0$19686$426a34cc@news.free.fr> References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: On 2/11/2011 4:24 PM, LL.Snark wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it in python several ways : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=0 > while t[i]>=t[0] : i+=1 This will raise IndexError when i gets too big. > ... not pythonic I think... > > Or : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=[j for j in range(len(t)) if t[j] References: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> Message-ID: On 2/11/2011 6:10 PM, Benjamin S Wolf wrote: > It occurred to me as I was writing a for loop that I would like to > write it in generator comprehension syntax, eg. > > for a in b if c: Already proposed and rejected. See archives for python-ideas or the gmane.comp.python.ideas mirror. -- Terry Jan Reedy From research at johnohagan.com Sat Feb 12 00:32:01 2011 From: research at johnohagan.com (John O'Hagan) Date: Sat, 12 Feb 2011 05:32:01 +0000 Subject: Reassign or discard Popen().stdout from a server process In-Reply-To: References: Message-ID: <201102120532.02385.research@johnohagan.com> On Fri, 11 Feb 2011, Nobody wrote: > On Thu, 10 Feb 2011 08:35:24 +0000, John O'Hagan wrote: > >> > But I'm still a little curious as to why even unsuccessfully > >> > attempting to reassign stdout seems to stop the pipe buffer from > >> > filling up. > >> > >> It doesn't. If the server continues to run, then it's ignoring/handling > >> both SIGPIPE and the EPIPE error. Either that, or another process has > >> the read end of the pipe open (so no SIGPIPE/EPIPE), and the server is > >> using non-blocking I/O or select() so that it doesn't block writing its > >> diagnostic messages. > > > > The server fails with stdout=PIPE if I don't keep reading it, but > > doesn't fail if I do stdout=anything (I've tried files, strings, > > integers, and None) soon after starting the process, without any other > > changes. How is that consistent with either of the above conditions? I'm > > sure you're right, I just don't understand. > > What do you mean by "fail". I wouldn't be surprised if it hung, due to the > write() on stdout blocking. If you reassign the .stdout member, the > existing file object is likely to become unreferenced, get garbage > collected, and close the pipe, which would prevent the server from > blocking (the write() will fail rather than blocking). > > If the server puts the pipe into non-blocking mode, write() will fail with > EAGAIN if you don't read it but with EPIPE if you close the pipe. The > server may handle these cases differently. By "fail" I mean the server, which is the Fluidsynth soundfont rendering program, stops producing sound in a way consistent with the blocked write() as you describe. It continues to read stdin; in fact, Ctrl+C-ing out of the block produces all the queued sounds at once. What I didn't realise was that the (ineffective) reassignment of stdout has the side-effect of closing it by dereferencing it, as you explain above. I asked on the Fluidsynth list and currently it ignores if the pipe it's writing to has been closed . All makes sense now, thanks. John From drsalists at gmail.com Sat Feb 12 00:47:32 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 11 Feb 2011 21:47:32 -0800 Subject: Class or Dictionary? In-Reply-To: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Feb 11, 2011 at 4:13 PM, Steven D'Aprano wrote: > On Fri, 11 Feb 2011 10:15:27 -0800, Dan Stromberg wrote: > > >> I'd use a class rather than a dictionary - because with a class, pylint >> (and perhaps PyChecker and pyflakes?) should be able to detect typos >> upfront. > > *Some* typos. Certainly not all. The salient bit is not that all typos are (or are not) caught, but that significantly more typos are caught before they cause a blowup in production. > The more complex the code -- and with 100 or so parameters, this sounds > pretty damn complex -- there is a non-negligible risk of mistakenly using > the wrong name. Unless pylint now has a "do what I mean, not what I say" > mode, it can't save you from typos like this: > > params.employerID = 23 > params.employeeID = 42 > # much later > if params.employeeID == 23: > ? ?# Oops, I meant employ*er*ID > ? ?... No, and yes, and no. 1) No: Pylint can frequently catch variables that are used before they are set or set but never used 2) Yes: If you write the wrong variable, and it is read somewhere afterward, you've still got a typo that's essentially a logic bug in how it manifests 3) No: You should not use variable names that differ by only a single character, or are too easy to "thinko" for each other - EG it's better to use params.companyID, params.supervisorID and params.workerID; these are clearly distinct. >> With a dictionary, typos remain runtime timebombs. > > Are your unit tests broken? You should fix that and not rely on just > pylint to detect bugs. Unit tests will help protect you against many more > bugs than just typos. Unit tests do not replace static analysis; they are complementary techniques. I started out in the manifestly-typed world. Then I moved into mostly python and bash, without any sort of static analysis, and loved it. More recently, I've been using python with static analysis, and I've been wondering why I lived without for so long. That doesn't imply a rejection of duck typing - it merely means I don't want my code embarrassing me unnecessarily (though I confess, I find Haskell and the ML family very interesting for their static, _inferred_ typing). It's a rare program of much size that can be tested so thoroughly that static analysis is 100% obviated - especially in the reporting of error conditions. An accidental traceback when you're trying to output an important detail related to one of a few thousand error conditions is embarrassing, and frequently could be prevented with pylint. Also, pylint tends to run much faster than the large battery of automated tests I prefer to set up. IOW, it can quickly catch many kinds of trivial blunders before incurring the development-time expense of running the full test suite. > Besides, and I quote... > > "I find it amusing when novice programmers believe their main job is > preventing programs from crashing. ... More experienced programmers > realize that correct code is great, code that crashes could use > improvement, but incorrect code that doesn't crash is a horrible > nightmare." -- Chris Smith LOL. Irrespective of some crashes being beneficial, the fact remains that easily avoided, nonessential crashes should be avoided. Pylint enables this to be done for an important class of errors. To eliminate them quickly and painlessly isn't precisely an attribute of a novice. Did you have some sort of bad experience with pylint? Do you resent the 20 minutes it takes to set it up? From steve+comp.lang.python at pearwood.info Sat Feb 12 01:20:03 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Feb 2011 06:20:03 GMT Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d562693$0$29980$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Feb 2011 21:47:32 -0800, Dan Stromberg wrote: > Did you have some sort of bad experience with pylint? Do you resent the > 20 minutes it takes to set it up? If you read my post more carefully and less defensively, you'll see that nothing I said was *opposed* to the use of pylint, merely that pylint is not a substitute of a good, thorough test suite. -- Steven From mdekauwe at gmail.com Sat Feb 12 01:24:56 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 11 Feb 2011 22:24:56 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> Steven, You make some good points and I don't disagree with you. The code is just a transfer from some older c++ code which had all sorts of windows menus etc, which isn't required and would make it impossible to run (again and again). It is not an especially complicated model, and no doubt there are bugs (though has been used widely for 20 years). Regarding customisation, in this case it is not a big deal. The way the code was (arguably poorly) written everything was declared globally. So in fact by using the .INI file to hold all of them I am probably saving myself a lot of time and I get away from globals. Most of those parameters are things I won't change, so I take your point but I see no issue in having the option frankly (and it is done so there is no effort now!). Ordinarily I might do what you said and having method/func calls with all the params like that, but I felt it was making the code look very untidy (i.e >5 vars with each call and needing to return > 5 vars). I then decided it would be better to pass a (single) dictionary or class object (not sure of correct word here) and I think by referencing it, e.g. params.light_ext_coeff it is as clear as passing all the values individually (i.e. you can track where the values came from). I am happy with this at any rate. Moreover it is what I am used to doing in C, where I would pass a single structure containing the necessary values. I also think this is quite standard? I am sure to interface with scientific libraries (such as GNU GSL) you pass structures in this way, I was just adopting this method. The point of this posting was just to ask those that know, whether it was a bad idea to use the class object in the way I had or was that OK? And if I should have just used a dictionary, why? Thanks. From bruno.piguet at gmail.com Sat Feb 12 02:06:49 2011 From: bruno.piguet at gmail.com (Bruno Piguet) Date: Fri, 11 Feb 2011 23:06:49 -0800 (PST) Subject: Arrays/List, filters, Pytho, Ruby References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <84b53408-2c5e-47c3-85e0-74a4a7c9cd60@k18g2000vbq.googlegroups.com> On 11 f?v, 22:24, "LL.Snark" wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x1000), "not found") or next((i for i, x in enumerate(t) if x>1000), None) or whatever matches your needs. Note that if you use the second optionnal argument of next, you'll need an additional pair of parentheses around the generator expression which is the first argument of next. Bruno. From douhetsukd at gmail.com Sat Feb 12 02:57:08 2011 From: douhetsukd at gmail.com (DouhetSukd) Date: Fri, 11 Feb 2011 23:57:08 -0800 (PST) Subject: Arrays/List, filters, Pytho, Ruby References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <22025f57-923b-4816-aa99-b9c106379d95@i39g2000prd.googlegroups.com> On Feb 11, 1:24?pm, "LL.Snark" wrote: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x > If you don't know Ruby, the second line means : > What is the index, in array t, of the first element x such that x > If can write it in python several ways : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=0 > while t[i]>=t[0] : i+=1 > > ... not pythonic I think... > > Or : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=[j for j in range(len(t)) if t[j] > ...too cryptic... > > I'm using Python 3. > > Thx [i for i,v in enumerate(t) if v < t[0]][0:1] empty list if no match. From javier.collado at gmail.com Sat Feb 12 03:18:18 2011 From: javier.collado at gmail.com (Javier Collado) Date: Sat, 12 Feb 2011 09:18:18 +0100 Subject: parse html rendered by js In-Reply-To: <1297412432.2316.57.camel@ocean-desktop> References: <1297412432.2316.57.camel@ocean-desktop> Message-ID: Hello, 2011/2/11 yanghq : > ? ?but for some pages rendered by js, like: You could use selenium or windmill to help you reproduce the contents of the web page in a browser so you can get the data from the DOM tree once the page has been rendered instead of by parsing the js. Best regards, Javier From andrea.crotti.0 at gmail.com Sat Feb 12 03:21:43 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sat, 12 Feb 2011 09:21:43 +0100 Subject: Class or Dictionary? In-Reply-To: <3d711f8b-8651-4add-84a6-c66a0a1dd64a@o32g2000prb.googlegroups.com> References: <3d711f8b-8651-4add-84a6-c66a0a1dd64a@o32g2000prb.googlegroups.com> Message-ID: <43B89542-F28F-4A24-920B-E9AC5D09B9C1@gmail.com> Il giorno 12/feb/2011, alle ore 00.45, Martin De Kauwe ha scritto: > Hi, > > yes I read a .INI file using ConfigParser, just similar sections (in > my opinion) to make one object which i can then pass to different > classes. E.G. Ok then I suggest configobj, less buggy and much more powerful than ConfigParser: http://www.voidspace.org.uk/python/configobj.html (and included from python 2.7). In this way you can also simply just carry around that dictionary, and it will be correctly typed if you validate the input. From ian.g.kelly at gmail.com Sat Feb 12 03:22:24 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 12 Feb 2011 01:22:24 -0700 Subject: For loop comprehensions In-Reply-To: <4d55f199$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> <1297468028.2517.3.camel@localhost.localdomain> <4d55f199$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Feb 11, 2011 at 7:34 PM, Steven D'Aprano wrote: > On Fri, 11 Feb 2011 16:59:52 -0700, Ian Kelly wrote: > >> Why not allow the same thing in for-loop conditions? > > Because new syntax and new language features means more work. Somebody > has to write the code, make sure that it doesn't break existing Python > code, test it for bugs, change the documentation, write regression tests > for it... And then, having done it for CPython, somebody else has to do > the same for IronPython, Jython, PyPy, CLPython, Stackless ... And all > that code has to be maintained. > > Because new syntax and features increases the size and complexity of the > Python code base, which means more bugs and more tests needed. > > Because new syntax and features increases the size and complexity of the > documentation needed, and hence increases the amount of things that need > to be learned. > > Because the guiding philosophy of Python is "there should be one, and > preferably only one, obvious way to do it". That doesn't mean that > multiple ways of doing it are forbidden (far from it!) but it does mean > that Python is conservative about adding multiple ways of spelling the > same thing. These things occurred to me, but they don't seem terribly compelling in this instance. We're not talking about adding an entirely new feature. We're talking about adapting an existing syntax feature to make it more widely useful. However, I've come up with what I think is a better reason: for x in a for y in b if condition(a, b): break else: found = False I can argue about what I think this code should do, but it certainly would not be clear to somebody unfamiliar with the syntax. Does the 'break' break out of the entire loop or just the inner part? Does the 'else' apply to the loop or to the 'if'? >> I think that >> anything that makes the language syntax more consistent is good. > > "A foolish consistency is the hobgoblin of little minds." If you think that quote is applicable here, then you misapprehend it. It has nothing whatsoever to do with uniformity as a language design principle. From nagle at animats.com Sat Feb 12 03:22:59 2011 From: nagle at animats.com (John Nagle) Date: Sat, 12 Feb 2011 00:22:59 -0800 Subject: Class or Dictionary? In-Reply-To: References: Message-ID: <4d564365$0$10544$742ec2ed@news.sonic.net> On 2/11/2011 6:56 AM, Martin De Kauwe wrote: > Hi, > > I have a series of parameter values which i need to pass throughout my > code (>100), in C I would use a structure for example. However in > python it is not clear to me if it would be better to use a dictionary > or build a class object? Personally I think accessing the values is > neater (visually) with an object rather than a dictionary, e.g. > > x = params['price_of_cats'] * params['price_of_elephants'] > > vs. > > x = params.price_of_cats * params.price_of_elephants Don't use a class as a dictionary. It causes various forms of grief. A dictionary will accept any string as a key, and has no reserved values. That's not true of class attributes. There are already many names in a class's namespace, including any functions of the class. Attribute syntax is restricted - there are some characters you can't use. Unicode attributes don't work right prior to Python 3. If the names are coming in from outside the program, there's a potential security hole if someone can inject names beginning with "__" and mess with the internal data structures of the class. And, of course, you can't use a name that's a reserved word in Python. (This last is forever causing grief in programs that parse HTML and try to use Python class attributes to represent HTML attributes. "class" is a common HTML attribute but a reserved word in Python. So such parsers have to have a special case for reserved words. Ugly.) In Javascript, classes are simply dictionaries, but Python is not Javascript. If you want a dictionary, use a "dict". John Nagle From bswolf at google.com Sat Feb 12 03:27:43 2011 From: bswolf at google.com (Benjamin S Wolf) Date: Sat, 12 Feb 2011 00:27:43 -0800 (PST) Subject: For loop comprehensions References: <554c2976-3af4-47a5-9db3-6207287526c2@y30g2000prf.googlegroups.com> Message-ID: On Feb 11, 3:47?pm, Westley Mart?nez wrote: > No, too confusing. Then people'll want compound loops e.g.: > > for a in b if c while d else return x: > ? ? print('Ha ha I'm so clever!') On Feb 11, 6:34?pm, Steven D'Aprano wrote: > There's nothing wrong with writing > > for x in iterable: > ? ? if condition(x): > ? ? ? ? process(x) > > The existing syntax is clear and obvious. There's no clear benefit to > shifting the if clause to the for expression: it complicates the parser, > and any benefit (if any!) only applies to a tiny fraction of for loops. > You save one line, which is trivial. You may save one indentation level, > which might, sometimes, be useful, but more often will also be trivial. > If there's an advantage to the suggestion, it's small. My reasons for suggesting this are more to align for-loop syntax with generator expression/list comprehension syntax than to add completely new functionality to for-loops. I had observed that what I had typed initially before realizing it was incorrect: for a in b if c: f(a) was equivalent (and nearly syntactically so) to [f(a) for a in b if c] minus the generation of a list. I understand there are more verbose ways to accomplish the same goal (such as filter or multiple lines). But there are also more verbose ways to construct a list (such as filter or multiple lines). That is why I decided to suggest it. On Feb 11, 7:54?pm, Terry Reedy wrote: > Already proposed and rejected. See archives for python-ideas or the > gmane.comp.python.ideas mirror. Thanks for pointing me in the right direction, and sorry for bringing it up a third (if not more!) time. For posterity, http://groups.google.com/group/python-ideas/browse_thread/thread/87eee156ac2c3a24/61621e7779b5b255, and earlier, http://groups.google.com/group/python-ideas/browse_thread/thread/e2d076fe35ece873/862674672b4de683. The latter brings up a good point about parsing: how will we be sure after reading 'for a in b if c' whether this is a comprehension or whether (b if c) begins a ternary expression (and we should expect a 'else d' to follow). Well, my suggestion is to bring for-loop syntax in line with comprehension syntax, and: >>> [a for a in range(10) if False else [99]] SyntaxError: invalid syntax >>> [a for a in (range(10) if False else [99])] [99] >>> for a in range(10) if False else [99]: print(a) ... 99 So as it stands now in 3.1, comprehensions don't permit the ternary expression without parenthesizing it, but for-loops do. So my suggestion would have the side effect of requiring parentheses for that latter expression, as comprehensions do. :/ Thanks again, --Ben From nagle at animats.com Sat Feb 12 03:29:33 2011 From: nagle at animats.com (John Nagle) Date: Sat, 12 Feb 2011 00:29:33 -0800 Subject: Shared memory python between two separate shell-launched processes In-Reply-To: <5abc8bca-b34a-4df1-bb26-6d1f4ca19b22@d16g2000yqd.googlegroups.com> References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> <8e97c42b-1c5c-4144-bb53-79163d183cfe@z3g2000prz.googlegroups.com> <5abc8bca-b34a-4df1-bb26-6d1f4ca19b22@d16g2000yqd.googlegroups.com> Message-ID: <4d5644ef$0$10574$742ec2ed@news.sonic.net> On 2/10/2011 9:21 AM, Charles Fox (Sheffield) wrote: > On Feb 10, 3:43 pm, Jean-Paul Calderone > wrote: >> On Feb 10, 9:30 am, "Charles Fox (Sheffield)" >> wrote: > Thanks Jean-Paul, I'll have a think about this. I'm not sure if it > will get me exactly what I want though, as I would need to keep > unloading my development module and reloading it, all within the > forked process, and I don't see how my debugger (and emacs pdb > tracking) will keep up with that to let me step though the code. > (this debugging is more about integration issues than single > functions, I have a bunch of unit tests for the little bits but > something is unhappy when I put them all together...) If you're having trouble debugging a sequential program, you do not want to add shared memory to the problem. John Nagle From mdekauwe at gmail.com Sat Feb 12 04:04:40 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sat, 12 Feb 2011 01:04:40 -0800 (PST) Subject: Class or Dictionary? References: <4d564365$0$10544$742ec2ed@news.sonic.net> Message-ID: <225cb891-0385-4d0d-91a0-213dd8b1b86c@o18g2000prh.googlegroups.com> On Feb 12, 7:22?pm, John Nagle wrote: > On 2/11/2011 6:56 AM, Martin De Kauwe wrote: > > > Hi, > > > I have a series of parameter values which i need to pass throughout my > > code (>100), in C I would use a structure for example. However in > > python it is not clear to me if it would be better to use a dictionary > > or build a class object? Personally I think accessing the values is > > neater (visually) with an object rather than a dictionary, e.g. > > > x = params['price_of_cats'] * params['price_of_elephants'] > > > vs. > > > x = params.price_of_cats * params.price_of_elephants > > ? ? Don't use a class as a dictionary. ?It causes various forms > of grief. ?A dictionary will accept any string as a key, and > has no reserved values. ? That's not true of class attributes. > There are already many names in a class's namespace, including > any functions of the class. ?Attribute syntax is restricted - > there are some characters you can't use. ?Unicode attributes > don't work right prior to Python 3. ?If the names are coming > in from outside the program, there's a potential security > hole if someone can inject names beginning with "__" and > mess with the internal data structures of the class. > And, of course, you can't use a name that's a reserved > word in Python. > > ? ? (This last is forever causing grief in programs that > parse HTML and try to use Python class attributes to > represent HTML attributes. ?"class" is a common HTML > attribute but a reserved word in Python. ?So such parsers > have to have a special case for reserved words. ?Ugly.) > > ? ? In Javascript, classes are simply dictionaries, but Python > is not Javascript. ?If you want a dictionary, use a "dict". > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle OK this was what I was after, thanks. I shall rewrite as dictionaries then given what you have said. From mdekauwe at gmail.com Sat Feb 12 04:06:11 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sat, 12 Feb 2011 01:06:11 -0800 (PST) Subject: Class or Dictionary? References: <3d711f8b-8651-4add-84a6-c66a0a1dd64a@o32g2000prb.googlegroups.com> Message-ID: <0e22259e-d1b6-4685-80ad-24a306ffd33b@k17g2000pre.googlegroups.com> On Feb 12, 7:21?pm, Andrea Crotti wrote: > Il giorno 12/feb/2011, alle ore 00.45, Martin De Kauwe ha scritto: > > > Hi, > > > yes I read a .INI file using ConfigParser, just similar sections (in > > my opinion) to make one object which i can then pass to different > > classes. E.G. > > Ok then I suggest configobj, less buggy and much more powerful than ConfigParser:http://www.voidspace.org.uk/python/configobj.html > > (and included from python 2.7). > In this way you can also simply just carry around that dictionary, and it will be correctly > typed if you validate the input. That is interesting however I am using python 2.6 so I guess I shall have to stick as I am for the moment. I think the way I used it above was quite straight forward? It seemed OK? What are the issues? From mdekauwe at gmail.com Sat Feb 12 04:20:31 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sat, 12 Feb 2011 01:20:31 -0800 (PST) Subject: Class or Dictionary? References: <3d711f8b-8651-4add-84a6-c66a0a1dd64a@o32g2000prb.googlegroups.com> <0e22259e-d1b6-4685-80ad-24a306ffd33b@k17g2000pre.googlegroups.com> Message-ID: On Feb 12, 8:06?pm, Martin De Kauwe wrote: > On Feb 12, 7:21?pm, Andrea Crotti wrote: > > > Il giorno 12/feb/2011, alle ore 00.45, Martin De Kauwe ha scritto: > > > > Hi, > > > > yes I read a .INI file using ConfigParser, just similar sections (in > > > my opinion) to make one object which i can then pass to different > > > classes. E.G. > > > Ok then I suggest configobj, less buggy and much more powerful than ConfigParser:http://www.voidspace.org.uk/python/configobj.html > > > (and included from python 2.7). > > In this way you can also simply just carry around that dictionary, and it will be correctly > > typed if you validate the input. > > That is interesting however I am using python 2.6 so I guess I shall > have to stick as I am for the moment. I think the way I used it above > was quite straight forward? It seemed OK? What are the issues? Ignore that I have just tested it (it works in 2.6), much better! Thanks!! From osborne6 at gmail.com Sat Feb 12 08:57:37 2011 From: osborne6 at gmail.com (john) Date: Sat, 12 Feb 2011 05:57:37 -0800 (PST) Subject: parse html rendered by js In-Reply-To: Message-ID: Even though I've never tried it, you may want to look into running the html thru a separate javascript engine, like spidermonkey or rhino, and then parse the results of that. On Friday, February 11, 2011 2:20:32 AM UTC-6, yanghq wrote: > hi, > I wanna get attribute value like href,src... in html. > > for simple html page libxml2dom can help me parse it into dom, and > get what I want; > > but for some pages rendered by js, like: > > document.write( > ' onUnload="end()" onResize="change()">'+ > ''+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > ''+ > ''+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > ' src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > '' > ) > how can I get the atrribute value of 'src', thank you for any help. > From askutt at gmail.com Sat Feb 12 09:19:24 2011 From: askutt at gmail.com (Adam Skutt) Date: Sat, 12 Feb 2011 06:19:24 -0800 (PST) Subject: Shared memory python between two separate shell-launched processes References: <0bb873ab-de4f-42f2-b407-877731655f0c@n1g2000yqm.googlegroups.com> <8e97c42b-1c5c-4144-bb53-79163d183cfe@z3g2000prz.googlegroups.com> <5abc8bca-b34a-4df1-bb26-6d1f4ca19b22@d16g2000yqd.googlegroups.com> <4d5644ef$0$10574$742ec2ed@news.sonic.net> Message-ID: On Feb 12, 3:29?am, John Nagle wrote: > > ? ? If you're having trouble debugging a sequential program, > you do not want to add shared memory to the problem. No, you don't want to add additional concurrent threads of execution. But he's not doing that, he's just preloading stuff into RAM. It's not different from using memcached, or sqlite, or any other database for that matter. Adam From titiamihaesei at gmail.com Sat Feb 12 09:35:36 2011 From: titiamihaesei at gmail.com (titia) Date: Sat, 12 Feb 2011 06:35:36 -0800 (PST) Subject: Led Zeppelin Message-ID: <776a0aa7-ac75-4957-aa87-dcb651e08821@s11g2000prs.googlegroups.com> If you like the music of Led Zeppelin,this is a good place: http://titia-ledzeppelin.blogspot.com/ From mdekauwe at gmail.com Sat Feb 12 12:08:04 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sat, 12 Feb 2011 09:08:04 -0800 (PST) Subject: Unpacking multiple dictionaries in a function? Message-ID: <2b13906e-92f7-4f8b-8ee2-b8641e27ec2e@d23g2000prj.googlegroups.com> Hi, Is there a better way to unpack more than one dictionary in a function than... def unpack_dicts(f): def wrapper(*old_dicts): dict={} for d in old_dicts: dict.update(d) return f(**dict) return wrapper @unpack_dicts def some_func(a=None, b=None, c=None): print a, b, c d1 = {'a': 20.0, 'b': '-1'} d2 = {'c': 33.0} some_func(d1, d2) thanks From jeandaniel.browne at gmail.com Sat Feb 12 12:22:18 2011 From: jeandaniel.browne at gmail.com (Jean-Daniel) Date: Sat, 12 Feb 2011 18:22:18 +0100 Subject: executing a function with feeding its global variables Message-ID: Hello, I am writing a small framework where the user which writes a function can expect some global variable to be set in the function namespace. The user has to write a function like this: """ # function.py from framework import, command, run @command def myfunc(): print HOST if __name__=="__main__": run() """ command() registers the function, and run() evaluates or execute the function within an environment or a namespace where HOST has been automagically set. Question: how can write run in a way that when using run() in a script, the decorated function will be run with the special names made available? Here is the code for this, which does not work as intended because the 'HOST' can not be found when evaluating the decorated function """ # framework.py HOST = '192.168.0.1' PORT = 12345 commands = [] def command(f): commands.append(f) return f def run(): for f in commands: assert globals()['HOST'] exec 'f()' in globals(),locals() if __name__=='__main__': @command def info(): print HOST,PORT run() """ Note that the assert makes sure the HOST variable is indeed present in the globals when running the function. When running function.py, I get an NameError exception. When I put the func function in the framework module and execute framework.py as a script, this works fine, the global HOST is available in the func namespace which gets printed. I tried many combinations of eval() or exec as well as many combinations for the globals() and locals() mapping fed to eval/exec without success. Thank you for your help From tjreedy at udel.edu Sat Feb 12 13:12:50 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 12 Feb 2011 13:12:50 -0500 Subject: Class or Dictionary? In-Reply-To: <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> Message-ID: On 2/12/2011 1:24 AM, Martin De Kauwe wrote: > The point of this posting was just to ask those that know, whether it > was a bad idea to use the class object in the way I had or was that > OK? And if I should have just used a dictionary, why? Did you miss my suggestion to use a module rather than a class? Modules do not have some of the disadvantages of classes listed by J. Nagle. -- Terry Jan Reedy From __peter__ at web.de Sat Feb 12 13:25:31 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 12 Feb 2011 19:25:31 +0100 Subject: executing a function with feeding its global variables References: Message-ID: Jean-Daniel wrote: > Hello, > > I am writing a small framework where the user which writes a function > can expect some global variable to be set in the function namespace. > > The user has to write a function like this: > """ > # function.py > from framework import, command, run > > @command > def myfunc(): > print HOST > > if __name__=="__main__": > run() > """ > > command() registers the function, and run() evaluates or execute the > function within an environment or a namespace where HOST has been > automagically set. > > Question: how can write run in a way that when using run() in a > script, the decorated function will be run with the special names made > available? > > Here is the code for this, which does not work as intended because the > 'HOST' can not be found when evaluating the decorated function > > """ > # framework.py > HOST = '192.168.0.1' > PORT = 12345 > > commands = [] > > def command(f): > commands.append(f) > return f > > def run(): > for f in commands: > assert globals()['HOST'] > exec 'f()' in globals(),locals() > > if __name__=='__main__': > > @command > def info(): > print HOST,PORT > > run() > """ > > Note that the assert makes sure the HOST variable is indeed present in > the globals when running the function. When running function.py, I get > an NameError exception. When I put the func function in the framework > module and execute framework.py as a script, this works fine, the > global HOST is available in the func namespace which gets printed. I > tried many combinations of eval() or exec as well as many combinations > for the globals() and locals() mapping fed to eval/exec without > success. Every module has its own global namespace, and a function is looking for global variables in the namespace it is defined in, not the one where the function is called from. A function defined in Python carries its global namespace with it as the __globals__ attribute (func_globals in older Python versions). def run(): for f in commands: f.__globals__.update(HOST=HOST, PORT=PORT) f() Note that every function in the function's module will see the extra variables. Peter From __peter__ at web.de Sat Feb 12 13:28:56 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 12 Feb 2011 19:28:56 +0100 Subject: Unpacking multiple dictionaries in a function? References: <2b13906e-92f7-4f8b-8ee2-b8641e27ec2e@d23g2000prj.googlegroups.com> Message-ID: Martin De Kauwe wrote: > Is there a better way to unpack more than one dictionary in a function > than... > > def unpack_dicts(f): > def wrapper(*old_dicts): > dict={} > for d in old_dicts: > dict.update(d) > return f(**dict) > return wrapper > > @unpack_dicts > def some_func(a=None, b=None, c=None): > print a, b, c > > d1 = {'a': 20.0, 'b': '-1'} > d2 = {'c': 33.0} > > some_func(d1, d2) > > thanks If you had shown a solution involving >>> dicts = [dict(a=1, b=2, c=3), dict(a=10, b=20, z=40), dict(a=100, t=500)] >>> reduce(lambda a, d: a.update(d) or a, dicts, {}) {'a': 100, 'c': 3, 'b': 20, 't': 500, 'z': 40} I would have pointed out your approach. So yes, I think you have already found the best solution. From clp2 at rebertia.com Sat Feb 12 13:31:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 12 Feb 2011 10:31:59 -0800 Subject: Unpacking multiple dictionaries in a function? In-Reply-To: <2b13906e-92f7-4f8b-8ee2-b8641e27ec2e@d23g2000prj.googlegroups.com> References: <2b13906e-92f7-4f8b-8ee2-b8641e27ec2e@d23g2000prj.googlegroups.com> Message-ID: On Sat, Feb 12, 2011 at 9:08 AM, Martin De Kauwe wrote: > Hi, > > Is there a better way to unpack more than one dictionary in a function > than... > > def unpack_dicts(f): > ? ?def wrapper(*old_dicts): > ? ? ? ?dict={} I wouldn't call the variable "dict" since that clashes with the name of the built-in type. > ? ? ? ?for d in old_dicts: > ? ? ? ? ? ?dict.update(d) > ? ? ? ?return f(**dict) > ? ?return wrapper > > @unpack_dicts > def some_func(a=None, b=None, c=None): > ? ?print a, b, c > > d1 = {'a': 20.0, 'b': '-1'} > d2 = {'c': 33.0} > > some_func(d1, d2) Aside from slight variants on this approach, no, there's not really a better way to do it. There's no built-in way to do it because different users might want different dict merging algorithms, such as: - multiple values for the same key is an error - multiple values for the same key are combined into a list/set of values - entries in earlier dicts clobber those in later dicts - entries in later dicts clobber those in earlier dicts Python has "In the face of ambiguity, refuse the temptation to guess." and "Explicit is better than implicit." among its design principles, and hence provides no default solution here, requiring the user to specify the behavior explicitly by doing the merging themselves. Cheers, Chris -- http://blog.rebertia.com From aspineux at gmail.com Sat Feb 12 13:47:50 2011 From: aspineux at gmail.com (aspineux) Date: Sat, 12 Feb 2011 10:47:50 -0800 (PST) Subject: generating .zip including __main__.py file in top root using distutils Message-ID: <4d634b43-8438-4eed-8c69-38fdb268e520@z20g2000yqe.googlegroups.com> Python 2.6 can run a zip file, searching for __main__.py in the root of the zip archive and running it. How can I create such an archive using distutils (and not setuptools) ? If I use # python setup.py bdist --format=zip I get a "dumb" zip file with a deep tree structure from "/" and I cannot put the __main__.py in the root archive If I use # python setup.py sdist --format=zip I get a more compact tree. But the tree start bellow directory named "mypackage-version", my-package-1.0/ setup.py __main__.py ........ If I use setuptool, generating .EGG I get exacly what I want ! But I read it is bad to use setuptool and EGGs since pip is available :-) I was hopping distutils have been updated when adding the zip trick, but I didn't find the trick. Help From subhakolkata1234 at gmail.com Sat Feb 12 15:06:07 2011 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 12 Feb 2011 12:06:07 -0800 (PST) Subject: Question on Creating exe file with py2exe Message-ID: <494b6577-09ea-45c7-8b22-5f5d10061a78@x4g2000prf.googlegroups.com> Dear Room, I am using Windows XP (SP2) and a Python Version "Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32". I was looking to create exe files. Reviewing various posts here, I felt py2exe may be the best thing I can opt for. But for Python2.6 I found the following note in the py2exe tutorial: "For Python 2.6, the DLL you need is called MSVCR90.dll. Py2exe is not able to automatically include this DLL in your dist directory, so you must provide it yourself. To complicate things, there is more than one version of this DLL in existance, each with the same filename. You need the same version that the Python interpreter was compiled with, which is version 9.0.21022.8. Through the remainder of these instructions, hover your mouse over the dll file (or the vcredist_x86.exe installer executable) to confirm which version you've got. " My questions are: (i) From where I can download "MSVCR90.dll" ? Is there any trusted site? (ii) How to install the same? (iii) Would py2exe work fine if I install it? (iv) Is there any other exe creating program which does not have all these problems? As it is a room for expert python developers, I felt to ask you, if any one can kindly find some time to resolve my query, I would be honored. Thanks in Advance, Best Regards, Subhabrata. From aspineux at gmail.com Sat Feb 12 15:29:33 2011 From: aspineux at gmail.com (aspineux) Date: Sat, 12 Feb 2011 12:29:33 -0800 (PST) Subject: Question on Creating exe file with py2exe References: <494b6577-09ea-45c7-8b22-5f5d10061a78@x4g2000prf.googlegroups.com> Message-ID: <7549e107-d7c0-488e-b164-fe6cf11cb498@n1g2000yqm.googlegroups.com> Hi I'm releasing a .exe made with py2exe myself an got this problem too. 99% of the time the required DLL is already installed by another application and you don't need to care about it. The 1% is about empty or fresh windows install (server most of the time) For them, I provide a link to the M$ vcredist and a warning in my download page asking them to install it them self. Take a look at my site for the vcredist link : http://www.magikmon.com/mksbackup/download.en.html Regards Alain On Feb 12, 9:06?pm, joy99 wrote: > Dear Room, > > I am using Windows XP (SP2) and a Python Version "Python 2.6.5 > (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on > win32". > > I was looking to create exe files. Reviewing various posts here, I > felt py2exe may be the best thing I can opt for. > > But for Python2.6 I found the following note in the py2exe tutorial: > "For Python 2.6, the DLL you need is called MSVCR90.dll. Py2exe is not > able to automatically include this DLL in your dist directory, so you > must provide it yourself. > > To complicate things, there is more than one version of this DLL in > existance, each with the same filename. You need the same version that > the Python interpreter was compiled with, which is version > 9.0.21022.8. Through the remainder of these instructions, hover your > mouse over the dll file (or the vcredist_x86.exe installer executable) > to confirm which version you've got. " > > My questions are: > (i) From where I can download "MSVCR90.dll" ? Is there any trusted > site? > (ii) How to install the same? > (iii) Would py2exe work fine if I install it? > (iv) Is there any other exe creating program which does not have all > these problems? > > As it is a room for expert python developers, I felt to ask you, if > any one can kindly find some time to resolve my query, I would be > honored. > > Thanks in Advance, > Best Regards, > Subhabrata. From no.email at nospam.invalid Sat Feb 12 15:33:28 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 12 Feb 2011 12:33:28 -0800 Subject: Unpacking multiple dictionaries in a function? References: <2b13906e-92f7-4f8b-8ee2-b8641e27ec2e@d23g2000prj.googlegroups.com> Message-ID: <7x7hd5xaav.fsf@ruckus.brouhaha.com> Martin De Kauwe writes: > def wrapper(*old_dicts): > dict={} > for d in old_dicts: > dict.update(d) > return f(**dict) Untested: from itertools import chain def wrapper(*old_dicts): return f(**dict(chain(d.iteritems() for d in old_dicts))) From __peter__ at web.de Sat Feb 12 15:51:45 2011 From: __peter__ at web.de (Peter Otten) Date: Sat, 12 Feb 2011 21:51:45 +0100 Subject: Unpacking multiple dictionaries in a function? References: <2b13906e-92f7-4f8b-8ee2-b8641e27ec2e@d23g2000prj.googlegroups.com> <7x7hd5xaav.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Martin De Kauwe writes: >> def wrapper(*old_dicts): >> dict={} >> for d in old_dicts: >> dict.update(d) >> return f(**dict) > > Untested: > > from itertools import chain > def wrapper(*old_dicts): > return f(**dict(chain(d.iteritems() for d in old_dicts))) I think you need chain.from_iterable() instead of chain(). From arnodel at gmail.com Sat Feb 12 18:00:25 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 12 Feb 2011 23:00:25 +0000 Subject: Arrays/List, filters, Pytho, Ruby References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <87aai0c0za.fsf@gmail.com> "LL.Snark" writes: > Hi, > > I'm looking for a pythonic way to translate this short Ruby code : > t=[6,7,8,6,7,9,8,4,3,6,7] > i=t.index {|x| x In Python3: >>> t = [6,7,8,6,7,9,8,4,3,6,7] >>> next(filter(t[0].__gt__, t)) 4 -- Arnaud From jeandaniel.browne at gmail.com Sat Feb 12 18:09:20 2011 From: jeandaniel.browne at gmail.com (Jean-Daniel) Date: Sun, 13 Feb 2011 00:09:20 +0100 Subject: executing a function with feeding its global variables In-Reply-To: References: Message-ID: On Sat, Feb 12, 2011 at 7:25 PM, Peter Otten <__peter__ at web.de> wrote: > Jean-Daniel wrote: > >> Hello, >> >> I am writing a small framework where the user which writes a function >> can expect some global variable to be set in the function namespace. >> >> The user has to write a function like this: >> """ >> # function.py >> from framework import, command, run >> >> @command >> def myfunc(): >> ? ? print HOST >> >> if __name__=="__main__": >> ? ? run() >> """ >> >> command() registers the function, and run() evaluates or execute the >> function within an environment or a namespace where HOST has been >> automagically set. >> >> Question: how can write run in a way that when using run() in a >> script, the decorated function will be run with the special names made >> available? >> >> Here is the code for this, which does not work as intended because the >> 'HOST' can not be found when evaluating the decorated function >> >> """ >> # framework.py >> HOST = '192.168.0.1' >> PORT = 12345 >> >> commands = [] >> >> def command(f): >> ? ? commands.append(f) >> ? ? return f >> >> def run(): >> ? ? for f in commands: >> ? ? ? ? assert globals()['HOST'] >> ? ? ? ? exec 'f()' in globals(),locals() >> >> if __name__=='__main__': >> >> ? ? @command >> ? ? def info(): >> ? ? ? ? print HOST,PORT >> >> ? ? run() >> """ >> >> Note that the assert makes sure the HOST variable is indeed present in >> the globals when running the function. When running function.py, I get >> an NameError exception. When I put the func function in the framework >> module and execute framework.py as a script, this works fine, the >> global HOST is available in the func namespace which gets printed. I >> tried many combinations of eval() or exec as well as many combinations >> for the globals() and locals() mapping fed to eval/exec without >> success. > > Every module has its own global namespace, and a function is looking for > global variables in the namespace it is defined in, not the one where the > function is called from. A function defined in Python carries its global > namespace with it as the __globals__ attribute (func_globals in older Python > versions). > > def run(): > ? ?for f in commands: > ? ? ? ?f.__globals__.update(HOST=HOST, PORT=PORT) > ? ? ? ?f() > > Note that every function in the function's module will see the extra > variables. Cool, thanks. I read here: http://docs.python.org/reference/datamodel.html about the func_globals and how it is a read only attribute. I incorrectly thought that this dictionary was read only because the reference was read only. > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > From arnodel at gmail.com Sat Feb 12 18:11:08 2011 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sat, 12 Feb 2011 23:11:08 +0000 Subject: Arrays/List, filters, Pytho, Ruby References: <4d55a9b5$0$19686$426a34cc@news.free.fr> <87aai0c0za.fsf@gmail.com> Message-ID: <8762soc0hf.fsf@gmail.com> Arnaud Delobelle writes: > "LL.Snark" writes: > >> Hi, >> >> I'm looking for a pythonic way to translate this short Ruby code : >> t=[6,7,8,6,7,9,8,4,3,6,7] >> i=t.index {|x| x> > > In Python3: > >>>> t = [6,7,8,6,7,9,8,4,3,6,7] >>>> next(filter(t[0].__gt__, t)) > 4 Oops! I realised my mistake the moment I sent the reply. You can do this to get the index: >>> next(i for i, x in enumerate(t) if x < t[0]) 7 -- Arnaud From yanghq at neusoft.com Sat Feb 12 20:14:35 2011 From: yanghq at neusoft.com (yanghq) Date: Sun, 13 Feb 2011 09:14:35 +0800 Subject: parse html rendered by js In-Reply-To: References: Message-ID: <1297559675.1990.5.camel@ocean-desktop> There seems no Rhino for linux. Spidermonkey won't support document , window and something else in js, so it won't help me a lot. On Sat, 2011-02-12 at 05:57 -0800, john wrote: > Even though I've never tried it, you may want to look into running the html thru a separate javascript engine, like spidermonkey or rhino, and then parse the results of that. > > On Friday, February 11, 2011 2:20:32 AM UTC-6, yanghq wrote: > > hi, > > I wanna get attribute value like href,src... in html. > > > > for simple html page libxml2dom can help me parse it into dom, and > > get what I want; > > > > but for some pages rendered by js, like: > > > > document.write( > > ' > onUnload="end()" onResize="change()">'+ > > ''+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > ''+ > > ''+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > ' > src="../frame.html?rtfPossible=' + rtfPossibleString + '">'+ > > '' > > ) > > how can I get the atrribute value of 'src', thank you for any help. > > > > --------------------------------------------------------------------------------------------------- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. --------------------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From data.2 at rediff.com Sat Feb 12 20:34:58 2011 From: data.2 at rediff.com (gaurav) Date: Sat, 12 Feb 2011 17:34:58 -0800 (PST) Subject: Management careers earn cash. Message-ID: World class site leading rail engineers division jobs, government jobs and banking career. http://rojgars.webs.com/Railwayjobs.htm http://rojgars1.webs.com/gov.htm Great income in Management careers. Rush for Management careers. http://managementjobs.webs.com/pm.htm http://topcareer.webs.com/humanresourcemgmt.htm From kwa at kuwata-lab.com Sat Feb 12 20:37:39 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sun, 13 Feb 2011 10:37:39 +0900 Subject: [ANN] Benchmarker 3.0.1 released - a small benchmark utility Message-ID: Hi, I released Benchmarker 3.0.1. http://pypi.python.org/pypi/Benchmarker/ Benchmarker is a small utility to benchmark your code. *NOTICE* This release doesn't have compatibility with release 2.0.0. Download -------- http://pypi.python.org/pypi/Benchmarker/ Installation:: ## if you have installed easy_install: $ sudo easy_install Benchmarker ## or download Benchmarker-3.0.1.tar.gz and install it $ wget http://pypi.python.org/packages/source/B/Benchmarker/Benchmarker-3.0.1.tar.gz $ tar xzf Benchmarker-3.0.1.tar.gz $ cd Benchmarker-3.0.1/ $ sudo python setup.py install Example ------- ex0.py:: from benchmarker import Benchmarker, cmdopt cmdopt.parse() s1, s2, s3, s4, s5 = "Haruhi", "Mikuru", "Yuki", "Itsuki", "Kyon" with Benchmarker(width=20, loop=1000*1000) as bm: for _ in bm.empty(): ## empty loop pass for _ in bm('join'): sos = ''.join((s1, s2, s3, s4, s5)) for _ in bm('concat'): sos = s1 + s2 + s3 + s4 + s5 for _ in bm('format'): sos = '%s%s%s%s%s' % (s1, s2, s3, s4, s5) Output example:: $ python ex0.py -h # show help message of command-line optins $ python ex0.py ## benchmarker: release 3.0.1 (for python) ## python platform: darwin [GCC 4.2.1 (Apple Inc. build 5664)] ## python version: 2.7.1 ## python executable: /usr/local/python/2.7.1/bin/python ## user sys total real (Empty) 0.1600 0.0000 0.1600 0.1639 join 0.6500 0.0000 0.6500 0.6483 concat 0.5700 0.0000 0.5700 0.5711 format 0.7600 0.0000 0.7600 0.7568 ## Ranking real concat 0.5711 (100.0%) ************************* join 0.6483 ( 88.1%) ********************** format 0.7568 ( 75.5%) ******************* ## Ratio Matrix real [01] [02] [03] [01] concat 0.5711 100.0% 113.5% 132.5% [02] join 0.6483 88.1% 100.0% 116.7% [03] format 0.7568 75.5% 85.7% 100.0% Notice that empty loop times (user, sys, total, and real) are subtracted from other benchmark times automatically. For example:: =================================================== benchmark label real (second) --------------------------------------------------- join 0.6483 (= 0.8122 - 0.1639) concat 0.5711 (= 0.7350 - 0.1639) format 0.7568 (= 0.9207 - 0.1639) =================================================== See http://pypi.python.org/pypi/Benchmarker/ for details. Changes on release 3.0.1 ------------------------ * License is changed again to Public Domain. * Change Task class to pass 1-origin index to yield block when 'for _ in bm()' . * Fix a bug that 'for _ in bm()' raised error when loop count was not specified. * Fix a bug that 'for _ in bm()' raised RuntimeError on Python 3. Changes on release 3.0.0 ------------------------ * Rewrite entirely. * Enhanced to support command-line options. :: import benchmarker benchmarker.cmdopt.parse() You can show all command-line options by ``python file.py -h``. See README file for details. * Benchmarker.repeat() is obsolete. :: ## Old (obsolete) with Benchmarker() as bm: for b in bm.repeat(5, 1): with b('bench1'): .... ## New for bm in Benchmarker(repeat=5, extra=1): with bm('bench1'): .... * Changed to specify time (second) format. :: import benchmarker benchmarker.format.label_with = 30 benchmarker.format.time = '%9.4f' * Followings are removed. * Benchmark.stat * Benchmark.compared_matrix() * Benchmark.print_compared_matrix() Have fun! -- regards, makoto kuwata From miki.tebeka at gmail.com Sat Feb 12 20:57:54 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 12 Feb 2011 17:57:54 -0800 (PST) Subject: parse html rendered by js In-Reply-To: Message-ID: <92bd4d68-bd01-48b4-b68c-d7ef1bbdc1b5@glegroupsg2000goo.googlegroups.com> > There seems no Rhino for linux. Rhino is written in Java. "java -jar js.jar" works fine on my Linux machine. From miki.tebeka at gmail.com Sat Feb 12 20:57:54 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 12 Feb 2011 17:57:54 -0800 (PST) Subject: parse html rendered by js In-Reply-To: Message-ID: <92bd4d68-bd01-48b4-b68c-d7ef1bbdc1b5@glegroupsg2000goo.googlegroups.com> > There seems no Rhino for linux. Rhino is written in Java. "java -jar js.jar" works fine on my Linux machine. From mdekauwe at gmail.com Sat Feb 12 21:20:00 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sat, 12 Feb 2011 18:20:00 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> Message-ID: <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> On Feb 13, 5:12?am, Terry Reedy wrote: > On 2/12/2011 1:24 AM, Martin De Kauwe wrote: > > > The point of this posting was just to ask those that know, whether it > > was a bad idea to use the class object in the way I had or was that > > OK? And if I should have just used a dictionary, why? > > Did you miss my suggestion to use a module rather than a class? > Modules do not have some of the disadvantages of classes listed by J. Nagle. > > -- > Terry Jan Reedy Hi, sorry I did. I just re-read it, could you provide an example? Sorry i am having a major mind blank this morning (I think this is obvious!?). And it would meet all of the criteria outlined by John Nagle? From aryanbiz at gmail.com Sat Feb 12 21:49:30 2011 From: aryanbiz at gmail.com (aryanbiz) Date: Sat, 12 Feb 2011 18:49:30 -0800 (PST) Subject: INVITATION TO JOIN WEBPAGE OF BEST SELLING AUTHOR ON HEALTH Message-ID: <1827d682-0e48-458a-967a-c3b9d98fdad1@w7g2000pre.googlegroups.com> Hi Friends, Join FB Fan Page of Ms. Nancy Deville at http://www.facebook.com/nancydevilleauthor Nancy Deville is a bestselling health, fitness, and beauty writer whose voice is established in the real food movement. Nancy's first novel Karma is a psychological thriller about sex trafficking. Her mission is to inspire health and happiness Regards, Aryan From drsalists at gmail.com Sat Feb 12 22:45:55 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 12 Feb 2011 19:45:55 -0800 Subject: Class or Dictionary? In-Reply-To: <4d562693$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <4d562693$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Feb 11, 2011 at 10:20 PM, Steven D'Aprano wrote: > On Fri, 11 Feb 2011 21:47:32 -0800, Dan Stromberg wrote: > >> Did you have some sort of bad experience with pylint? ?Do you resent the >> 20 minutes it takes to set it up? > > If you read my post more carefully and less defensively, you'll see that > nothing I said was *opposed* to the use of pylint, merely that pylint is > not a substitute of a good, thorough test suite. Actually, I mentioned the value of pylint. Then you asked me if my unit tests were broken. What would you infer from such a question? From subhakolkata1234 at gmail.com Sun Feb 13 00:20:41 2011 From: subhakolkata1234 at gmail.com (joy99) Date: Sat, 12 Feb 2011 21:20:41 -0800 (PST) Subject: Question on Creating exe file with py2exe References: <494b6577-09ea-45c7-8b22-5f5d10061a78@x4g2000prf.googlegroups.com> <7549e107-d7c0-488e-b164-fe6cf11cb498@n1g2000yqm.googlegroups.com> Message-ID: <236bea12-00ef-4e30-b8df-ff33998874bd@o21g2000prn.googlegroups.com> On Feb 13, 1:29?am, aspineux wrote: > Hi > > I'm releasing a .exe made with py2exe myself an got this problem too. > 99% of the time the required DLL is already installed by another > application and you don't need to care about it. > The 1% is about empty or fresh windows install (server most of the > time) > For them, I provide a link to the M$ vcredist and a warning in my > download page asking them to install it them self. > > Take a look at my site for the vcredist link :http://www.magikmon.com/mksbackup/download.en.html > > Regards > > Alain > > On Feb 12, 9:06?pm, joy99 wrote: > > > Dear Room, > > > I am using Windows XP (SP2) and a Python Version "Python 2.6.5 > > (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on > > win32". > > > I was looking to create exe files. Reviewing various posts here, I > > felt py2exe may be the best thing I can opt for. > > > But for Python2.6 I found the following note in the py2exe tutorial: > > "For Python 2.6, the DLL you need is called MSVCR90.dll. Py2exe is not > > able to automatically include this DLL in your dist directory, so you > > must provide it yourself. > > > To complicate things, there is more than one version of this DLL in > > existance, each with the same filename. You need the same version that > > the Python interpreter was compiled with, which is version > > 9.0.21022.8. Through the remainder of these instructions, hover your > > mouse over the dll file (or the vcredist_x86.exe installer executable) > > to confirm which version you've got. " > > > My questions are: > > (i) From where I can download "MSVCR90.dll" ? Is there any trusted > > site? > > (ii) How to install the same? > > (iii) Would py2exe work fine if I install it? > > (iv) Is there any other exe creating program which does not have all > > these problems? > > > As it is a room for expert python developers, I felt to ask you, if > > any one can kindly find some time to resolve my query, I would be > > honored. > > > Thanks in Advance, > > Best Regards, > > Subhabrata. > > Hi Alain, Thank you for your product information. But, with my problem installation is okay. The first two steps: "from distutils.core import setup import py2exe" but as I am giving "setup(console=['file.py'])" the setup file is not being generated. It is giving some error messages. Any suggestions? Best Regards, Subhabrata. From clp2 at rebertia.com Sun Feb 13 01:10:28 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 12 Feb 2011 22:10:28 -0800 Subject: [ANN]: sahriswiki 0.8.1 (a Lightweight Wiki Engine) In-Reply-To: References: Message-ID: FYI: Your macro listing page seems to be broken: http://sahriswiki.org/Macros Cheers, Chris On Sat, Feb 12, 2011 at 2:13 PM, James Mills wrote: > Hello all, > > I'm pleased to announce the release of sahriswiki 0.8.1 > > This is a minor bug-fix release. > > For more information see the PyPi page: > > http://pypi.python.org/pypi/sahriswiki/ > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > ? ? ? ?Support the Python Software Foundation: > ? ? ? ?http://www.python.org/psf/donations/ > From tjreedy at udel.edu Sun Feb 13 02:35:04 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 13 Feb 2011 02:35:04 -0500 Subject: Class or Dictionary? In-Reply-To: <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> Message-ID: On 2/12/2011 9:20 PM, Martin De Kauwe wrote: > On Feb 13, 5:12 am, Terry Reedy wrote: >> On 2/12/2011 1:24 AM, Martin De Kauwe wrote: >> >>> The point of this posting was just to ask those that know, whether it >>> was a bad idea to use the class object in the way I had or was that >>> OK? And if I should have just used a dictionary, why? >> >> Did you miss my suggestion to use a module rather than a class? >> Modules do not have some of the disadvantages of classes listed by J. Nagle. >> >> -- >> Terry Jan Reedy > > Hi, sorry I did. I just re-read it, could you provide an example? I am not sure what you are asking. tkinter.contants is one example. > Sorry i am having a major mind blank this morning (I think this is > obvious!?). And it would meet all of the criteria outlined by John > Nagle? A module will work fine if but only if you commit yourself to having all keys be legal Python identifiers. But that is usually not a problem with configuration values. -- Terry Jan Reedy From hayesjdno3 at yahoo.com Sun Feb 13 05:06:15 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 02:06:15 -0800 (PST) Subject: files,folders,paths Message-ID: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> i have a samba server at home (acting as my test environment) with one of the 'shares' mounted as v: on my windows box. inside of that are 4 folders week[1-4]. i have created c:\users\name\backup , and put a few files/folders in there to test with. please ignore the wxpython parts of the script, the last 1/3, that part is functional. initial test was looking good. (in the code, ver011 source1, destination1) coping files/ folders and not clobbering files. going to version 12a, it seems like it is trying to copy the files under the folder, before making the folder. or doing the copy2 part before the copytree part. i dont know why it works on ver011, and not in ver12a, the only difference being the destination. facbac 011 facbac 012a Traceback (most recent call last): File "I:\college\spring11\capstone-project\facbac-012a.py", line 161, in button1Click backupall() File "I:\college\spring11\capstone-project\facbac-012a.py", line 81, in backupall shutil.copy2(filesource, filedest1) File "C:\Python27\lib\shutil.py", line 127, in copy2 copyfile(src, dst) File "C:\Python27\lib\shutil.py", line 82, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 2] No such file or directory: 'V:\\week2\\configs\ \apache2.conf' here, apache2.conf = c:\users\name\backup\config\apache2.conf trying to copy to v:\week2\config\apache2.conf but there is no v:\week2\config as it has not made the config folder yet i think the problem might be the \\ in the destination name. From aspineux at gmail.com Sun Feb 13 05:22:31 2011 From: aspineux at gmail.com (aspineux) Date: Sun, 13 Feb 2011 02:22:31 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> Message-ID: <9ba1d28f-6632-492d-9f96-ebd90c7c0bff@x18g2000yqe.googlegroups.com> Without trying to understand your code, I see one difference if not os.path.isfile(destination+leftover+fname): become if not os.path.isfile(destination+leftover): Regards On Feb 13, 11:06?am, ecu_jon wrote: > i have a samba server at home (acting as my test environment) with one > of the 'shares' mounted as v: on my windows box. inside of that are 4 > folders week[1-4]. i have created c:\users\name\backup , and put a few > files/folders in there to test with. please ignore the wxpython parts > of the script, the last 1/3, that part is functional. initial test was > looking good. (in the code, ver011 source1, destination1) coping files/ > folders and not clobbering files. going to version 12a, it seems like > it is trying to copy the files under the folder, before making the > folder. or doing the copy2 part before the copytree part. i dont know > why it works on ver011, and not in ver12a, the only difference being > the destination. > facbac 011 > facbac 012a > Traceback (most recent call last): > ? File "I:\college\spring11\capstone-project\facbac-012a.py", line > 161, in button1Click > ? ? backupall() > ? File "I:\college\spring11\capstone-project\facbac-012a.py", line 81, > in backupall > ? ? shutil.copy2(filesource, filedest1) > ? File "C:\Python27\lib\shutil.py", line 127, in copy2 > ? ? copyfile(src, dst) > ? File "C:\Python27\lib\shutil.py", line 82, in copyfile > ? ? with open(dst, 'wb') as fdst: > IOError: [Errno 2] No such file or directory: 'V:\\week2\\configs\ > \apache2.conf' > > here, apache2.conf = c:\users\name\backup\config\apache2.conf > trying to copy to v:\week2\config\apache2.conf > but there is no v:\week2\config > as it has not made the config folder yet > i think the problem might be the \\ in the destination name. From hayesjdno3 at yahoo.com Sun Feb 13 05:45:11 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 02:45:11 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <9ba1d28f-6632-492d-9f96-ebd90c7c0bff@x18g2000yqe.googlegroups.com> Message-ID: <42cafbad-c3aa-4aa4-a675-d0bb01fb1775@f18g2000yqd.googlegroups.com> i just tried changing that in ver12a, still get IOError: [Errno 2] No such file or directory: 'V:\\week2\\configs\ \apache2.conf' good catch tho as that is needed. thanks. weekchoice is used to pick week 1-4. really jsut returns 1-4. i plan to do full weekly backups with another script. getusername i was using when i was trying to build the path as part of a unc path. isdir/isfile did not play well with that. homedir returns the users home directory. works in xp,7, and linux. source and destination should be self explanatory. the backupall() gets called from clicking the button. for now its the meat and potatoes im working on. it is trying to recursively copy files/folders from source to dest. the for ... os.walk line digs through the backup folder. i use os.chgdir , os.getcwd and leftover to build the path for file/folder names on dest. basically start at c: \users\name\backup\somefolder and end with just somefolderadded to dest. if os.path.isdir(fname): checks if it is a folder. copytree is a recursive folder copy. elif os.path.isfile(fname): if it is a file. copy2 copies files and metadata. class MyForm(wx.Frame): and down is wxpython, that works. ( tho i will take suggestions but i know this is not the right forum to as questions for that part) From steve+comp.lang.python at pearwood.info Sun Feb 13 06:10:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Feb 2011 11:10:24 GMT Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <4d562693$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d57bc20$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sat, 12 Feb 2011 19:45:55 -0800, Dan Stromberg wrote: > On Fri, Feb 11, 2011 at 10:20 PM, Steven D'Aprano > wrote: >> On Fri, 11 Feb 2011 21:47:32 -0800, Dan Stromberg wrote: >> >>> Did you have some sort of bad experience with pylint? ?Do you resent >>> the 20 minutes it takes to set it up? >> >> If you read my post more carefully and less defensively, you'll see >> that nothing I said was *opposed* to the use of pylint, merely that >> pylint is not a substitute of a good, thorough test suite. > > Actually, I mentioned the value of pylint. Then you asked me if my unit > tests were broken. > > What would you infer from such a question? That I believed that you are using pylint as a substitute for unit tests, instead of in conjunction with unit tests. -- Steven From steve+comp.lang.python at pearwood.info Sun Feb 13 06:53:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Feb 2011 11:53:06 GMT Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> Message-ID: <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Feb 2011 02:06:15 -0800, ecu_jon wrote: > i have a samba server at home (acting as my test environment) with one > of the 'shares' mounted as v: on my windows box. inside of that are 4 > folders week[1-4]. i have created c:\users\name\backup , and put a few > files/folders in there to test with. please ignore the wxpython parts of > the script, the last 1/3, that part is functional. Please don't dump code on us and tell us to ignore parts of it. We're offering our time and experience without charging you, the least you can do is take the time to eliminate the irrelevant parts of the code yourself, and show us the smallest piece of code which demonstrates the problem. Doing so will not only demonstrate respect for others, but it might even help you solve the problem yourself. > initial test was > looking good. (in the code, ver011 source1, destination1) coping files/ > folders and not clobbering files. going to version 12a, it seems like it > is trying to copy the files under the folder, before making the folder. > or doing the copy2 part before the copytree part. i dont know why it > works on ver011, and not in ver12a, the only difference being the > destination. That's not exactly true, is it? I count at least three other differences: * facbac-012a.py imports getpass and defines a redundant getusername function (redundant because all it does is wrap getpass.getuser); * it also defines a function destination2 which is different from destination1, and uses that; * there's a difference in the call to os.path.isfile; I don't know if these are relevant. You say the difference between the script that works and the script that doesn't is the destination. And then you show an error that appears to be because the destination doesn't exist: > Traceback (most recent call last): > File "I:\college\spring11\capstone-project\facbac-012a.py", line > 161, in button1Click > backupall() > File "I:\college\spring11\capstone-project\facbac-012a.py", line 81, > in backupall > shutil.copy2(filesource, filedest1) > File "C:\Python27\lib\shutil.py", line 127, in copy2 > copyfile(src, dst) > File "C:\Python27\lib\shutil.py", line 82, in copyfile > with open(dst, 'wb') as fdst: > IOError: [Errno 2] No such file or directory: 'V:\\week2\\configs\ > \apache2.conf' Seems like an open and shut case to me. > here, apache2.conf = c:\users\name\backup\config\apache2.conf trying to > copy to v:\week2\config\apache2.conf but there is no v:\week2\config > as it has not made the config folder yet i think the problem might be > the \\ in the destination name. There is no double-backslash in the destination name. Backslashes are special in Python, and when displaying strings, they are escaped: >>> s = "x\yz" >>> len(s) 4 >>> s 'x\\yz' >>> print s x\yz Your suggestion, that the problem is that the config directory doesn't exist, sounds reasonable to me. Only you can test that, as we don't have access to your file system. -- Steven From subhakolkata1234 at gmail.com Sun Feb 13 07:29:23 2011 From: subhakolkata1234 at gmail.com (joy99) Date: Sun, 13 Feb 2011 04:29:23 -0800 (PST) Subject: Question on using cx_freeze Message-ID: Dear Room, I was trying to build an .exe file for my sample python scripting file "hello1.py". I felt using cx_freeze as py2exe was giving some problems for Python2.6, which I am using. I gave the following commands: >>> import sys >>> from cx_Freeze import setup, Executable >>> base = None if sys.platform == "win32": base = "Win32GUI" >>> setup( name = "hello1", version = "0.1", description = "Sample hello1 script", executables = [Executable("hello1.py", base = base)]) I am getting the following error messages: Traceback (most recent call last): File "", line 5, in executables = [Executable("hello1.py", base = base)]) File "D:\Python26\lib\site-packages\cx_Freeze\dist.py", line 360, in setup distutils.core.setup(**attrs) File "D:\Python26\lib\distutils\core.py", line 140, in setup raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg SystemExit: usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: --help [cmd1 cmd2 ...] or: --help-commands or: cmd --help error: no commands supplied My questions are: (i) What is the problem I am doing? (ii) How to overcome this error? I am using Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v. 1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information on Windows XP (SP 2). If any one can help me out I may be hugely helpful. Thanks in Advance, Best Regards, Subhabrata. From subhakolkata1234 at gmail.com Sun Feb 13 07:56:02 2011 From: subhakolkata1234 at gmail.com (joy99) Date: Sun, 13 Feb 2011 04:56:02 -0800 (PST) Subject: Question on running exe file in Python Message-ID: <54c757d5-ee82-46b4-bd59-06d0c9c9ac51@n16g2000prc.googlegroups.com> Dear Room, I am using Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v. 1500 32 bit (Intel)] on win32 on Windows XP (SP2). Trying to create an .exe file of my scripting file I had saved it as .exe instead of .py file. It seems created. But how to run it? I tried command prompt, seems unresponsive. Best Regards, Subhabrata. From davea at ieee.org Sun Feb 13 08:17:17 2011 From: davea at ieee.org (Dave Angel) Date: Sun, 13 Feb 2011 08:17:17 -0500 Subject: files,folders,paths In-Reply-To: <42cafbad-c3aa-4aa4-a675-d0bb01fb1775@f18g2000yqd.googlegroups.com> References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <9ba1d28f-6632-492d-9f96-ebd90c7c0bff@x18g2000yqe.googlegroups.com> <42cafbad-c3aa-4aa4-a675-d0bb01fb1775@f18g2000yqd.googlegroups.com> Message-ID: <4D57D9DD.60303@ieee.org> On 01/-10/-28163 02:59 PM, ecu_jon wrote: > i just tried changing that in ver12a, still get > IOError: [Errno 2] No such file or directory: 'V:\\week2\\configs\ > \apache2.conf' > good catch tho as that is needed. thanks. > weekchoice is used to pick week 1-4. really jsut returns 1-4. i plan > to do full weekly backups with another script. > getusername i was using when i was trying to build the path as part of > a unc path. isdir/isfile did not play well with that. > homedir returns the users home directory. works in xp,7, and linux. > source and destination should be self explanatory. > the backupall() gets called from clicking the button. for now its the > meat and potatoes im working on. it is trying to recursively copy > files/folders from source to dest. the for ... os.walk line digs > through the backup folder. i use os.chgdir , os.getcwd and leftover to > build the path for file/folder names on dest. basically start at c: > \users\name\backup\somefolder and end with just somefolderadded to > dest. > if os.path.isdir(fname): checks if it is a folder. copytree is a > recursive folder copy. > elif os.path.isfile(fname): if it is a file. copy2 copies files and > metadata. > class MyForm(wx.Frame): and down is wxpython, that works. ( tho i will > take suggestions but i know this is not the right forum to as > questions for that part) > I haven't tried to run your script, since much of it is Windows dependent, and I'm on Linux. So observations are just by inspection. I suspect your problem is that you're trying to change drives as well as directories. In Windows, there's a current directory on each drive, that Windows remembers. So changing directories on a different drive doesn't mean what you might think it does. I'd recommend doing no chdir()'s at all, and using only absolute paths. But I see other complications or maybe risks in the code, concentrating on function backupall(). You're using os.walk(), which walks through a whole tree of files. But then when you encounter a directory, you're doing a copytree(). So you'll be copying the same files many-many times. Similarly, you have logic for copying a single file, but you invoke it on a name from dirlist, which is a list of directories, so the isfile() probably never fires. os.walk() assumes the current directory is unchanged during its run. See: http://docs.python.org/library/os.html#module-os "walk() never changes the current directory, and assumes that its caller doesn?t either." You're not copying the files at the top level at all; you don't process the list called 'files', while you could probably safely copy *only* the files. Your name manipulations in this same function look risky, using replace when you presumably know that a string is either at the begin or end. In function homeDir(), you never return the value calculated in the try block. If you don't get an exception, you return None. DaveA From clp2 at rebertia.com Sun Feb 13 08:58:50 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 13 Feb 2011 05:58:50 -0800 Subject: Question on running exe file in Python In-Reply-To: <54c757d5-ee82-46b4-bd59-06d0c9c9ac51@n16g2000prc.googlegroups.com> References: <54c757d5-ee82-46b4-bd59-06d0c9c9ac51@n16g2000prc.googlegroups.com> Message-ID: On Sun, Feb 13, 2011 at 4:56 AM, joy99 wrote: > Dear Room, Just a friendly FYI: that's a strange salutation; comp.lang.python AKA python-list isn't a chat room, at least in the normal sense of the term. > I am using Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v. > 1500 32 bit (Intel)] on win32 on Windows XP (SP2). > > Trying to create an .exe file of my scripting file I had saved it > as .exe instead of .py file. It seems created. But how to run it? I > tried command prompt, seems unresponsive. You can't compile things to executables (i.e. machine code, i.e. .exe files) just by changing the file extension; you have to use a compiler to generate the .exe. Additionally, Python is normally an interpreted language; hence, it does not normally produce independent executables (unless possibly you're using a non-CPython implementation of Python). You can however generate self-contained executables for Python programs using special tools such as py2exe, cx_freeze, etc., which judging by your other post, you're already aware of. So, if you want to generate a .exe, you'll need to get one of those tools working. (Renaming a text .py file to a .exe results in your CPU trying to treat the text like it's binary machine code; since it's not machine code, the CPU ends up executing gibberish instructions, resulting in an error, freeze, or similar that causes the unresponsiveness you're observing.) Cheers, Chris -- http://blog.rebertia.com From subhakolkata1234 at gmail.com Sun Feb 13 09:16:40 2011 From: subhakolkata1234 at gmail.com (joy99) Date: Sun, 13 Feb 2011 06:16:40 -0800 (PST) Subject: Question on running exe file in Python References: <54c757d5-ee82-46b4-bd59-06d0c9c9ac51@n16g2000prc.googlegroups.com> Message-ID: <6b141501-9d75-42ce-83e9-d5502d58c257@r4g2000prm.googlegroups.com> Thanks for your reply. On Feb 13, 6:58?pm, Chris Rebert wrote: > On Sun, Feb 13, 2011 at 4:56 AM, joy99 wrote: > > Dear Room, > > Just a friendly FYI: that's a strange salutation; comp.lang.python AKA > python-list isn't a chat room, at least in the normal sense of the > term. I know that. It is a highly technical room. I have been visiting this room for last 4 yrs or so, greeted people in the same way, but someone felt hurt I saw for the first time! > > > I am using Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v. > > 1500 32 bit (Intel)] on win32 on Windows XP (SP2). > > > Trying to create an .exe file of my scripting file I had saved it > > as .exe instead of .py file. It seems created. But how to run it? I > > tried command prompt, seems unresponsive. > > You can't compile things to executables (i.e. machine code, i.e. .exe > files) just by changing the file extension; you have to use a compiler > to generate the .exe. Additionally, Python is normally an interpreted > language; hence, it does not normally produce independent executables > (unless possibly you're using a non-CPython implementation of Python). > You can however generate self-contained executables for Python > programs using special tools such as py2exe, cx_freeze, etc., which > judging by your other post, you're already aware of. So, if you want > to generate a .exe, you'll need to get one of those tools working. > > (Renaming a text .py file to a .exe results in your CPU trying to > treat the text like it's binary machine code; since it's not machine > code, the CPU ends up executing gibberish instructions, resulting in > an error, freeze, or similar that causes the unresponsiveness you're > observing.) > > Cheers, > Chris > --http://blog.rebertia.com All you have to get a solution. That's the goal. Not how approach should be. You may be more learned, but doing an .exe file works. I googled out and found the answer. But somehow, I am finding the people visiting this forum have either downsized, or their quality degraded. I often find a web search gives better answers. You can save as .pyw for .dll files. For .exe files, saving as .exe simply works, you can get the result by importing os, or by simply executing it from command prompt. Best Regards, Subhabrata. From sturlamolden at yahoo.no Sun Feb 13 11:40:31 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Sun, 13 Feb 2011 08:40:31 -0800 (PST) Subject: EPD 7.0 released References: Message-ID: <6a6a88a7-cbef-4b12-93e1-ba56a8cf7c0e@k9g2000yqi.googlegroups.com> EPD is great, at least for scientific users. There is just one installer, with everything we need, instead of struggling with dozens of libraries to download, configure and build. It is still Python 2.7 (not 3.1) due to libraries like SciPy. A subscription for EPD is also a contribution to the development of NumPy and SciPy. Sturla On 10 Feb, 02:00, Eric Stechmann wrote: > Hi, son. > > Don't know if this would be of any interest to you. ? Well, I suppose it does provide some interesting. > > I hope your physical get-together will help out. > > Love you, David. > > Dad > > On Feb 9, 2011, at 8:13 AM, Ilan Schnell wrote: > > > Hello, > > > I am pleased to announce that EPD (Enthought Python Distribution) > > version 7.0 has been released. ?This major release updates to > > Python 2.7, Intel Math Kernel Library 10.3.1, numpy 1.5.1, in > > addition to updates to many of the other packages included. > > Please find the complete list of additions, updates and bug fixes > > in the change log: > > > ? ? ? ?http://www.enthought.com/EPDChangelog.html > > > To find more information about EPD, as well as download a 30 day > > free trial, visit this page: > > > ? ? ? ?http://www.enthought.com/products/epd.php > > > About EPD > > --------- > > The Enthought Python Distribution (EPD) is a "kitchen-sink-included" > > distribution of the Python Programming Language, including over 90 > > additional tools and libraries. The EPD bundle includes NumPy, SciPy, > > IPython, 2D and 3D visualization, and many other tools. > > > ? ? ? ?http://www.enthought.com/products/epdlibraries.php > > > It is currently available as a single-click installer for Windows XP, > > Vista and 7, MacOS (10.5 and 10.6), RedHat 3, 4 and 5, as well as > > Solaris 10 (x86 and x86_64/amd64 on all platforms). > > > All versions of EPD (32 and 64-bit) are free for academic use. ?An > > annual subscription including installation support is available for > > individual and commercial use. ?Additional support options, including > > customization, bug fixes and training classes are also available: > > > ? ? ? ?http://www.enthought.com/products/support_level_table.php > > > - Ilan > > -- > >http://mail.python.org/mailman/listinfo/python-announce-list > > > ? ? ? ?Support the Python Software Foundation: > > ? ? ? ?http://www.python.org/psf/donations/ > > From andrea.crotti.0 at gmail.com Sun Feb 13 12:34:00 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sun, 13 Feb 2011 18:34:00 +0100 Subject: multiprocessing & more Message-ID: Hi everyone, I have a few questions about my implementation, which doesn't make me totally happy. Suppose I have a very long process, which during its executiong logs something, and the logs are is in n different files in the same directory. Now in the meanwhile I want to be able to do realtime analysis in python, so this is what I've done (simplifying): def main(): from multiprocessing import Value, Process is_over = Value('h', 0) Process(target=run, args=(conf, is_over)).start() # should also pass the directory with the results Process(target=analyze, args=(is_over, network, events, res_dir)).start() def run(): sim = subprocess.Popen(TEST_PAD, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = sim.communicate() ret = sim.wait() # at this point the simulation is over, independently from the result print "simulation over, can also stop the others" is_over.value = 1 def analyze(): ... First of all, does it make sense to use multiprocessing and a short value as boolean to check if the simulation is over or not? Then the other problem is that I need to read many files, and the idea was a sort of "tail -f", but on all of them at the same time. Since I have to keep track of the status for each of them I ended up with something like this: class LogFileReader(object): def __init__(self, log_file): self.log_file = log_file self.pos = 0 def get_line(self): src = open(self.log_file) src.seek(self.pos) lines = src.readlines() self.pos = src.tell() return lines which I'm also not really sure it's the best way, then in analyze() I have a dictionary which keeps track of all the "readers" log_readers = {} for out in glob(res_dir + "/*.out"): node = FILE_OUT.match(out).group(1) nodeid = hw_to_nodeid(node) log_readers[nodeid] = LogFileReader(out) Maybe having more separate processes might be more clean, but since I have to merge the data it might be a mess... As last thing to know when to start to analyze the data I thought about this while len(listdir(res_dir)) < len(network): sleep(0.2) which in theory it should be correct, when there are enough files as the number of nodes in the network everything should be written. BUT once every 5 times I get an error, telling me one file doens't exists. That means that for listdir the file is already there but trying to access to it gives error, how is that possible? THanks a lot, and sorry for the long mail From gerald.britton at gmail.com Sun Feb 13 13:05:04 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Sun, 13 Feb 2011 13:05:04 -0500 Subject: How can I print a traceback without raising an exception? Message-ID: In the following example, I raise an exception in function h() which prints a traceback. I would like to know how I can get a similar display on my terminal without raising an exception. That is, can I replace "raise Exception" in function h() with some sequence of instructions (possibly using the inspect module) that will generate a similar call trace of how I got to that point? Example: >>> def f(): ... g() ... >>> def g(): ... h() ... >>> def h(): ... raise Exception # Replace with something to generate a call trace ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f File "", line 2, in g File "", line 2, in h Exception >>> -- Gerald Britton From hayesjdno3 at yahoo.com Sun Feb 13 13:40:08 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 10:40:08 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <9ba1d28f-6632-492d-9f96-ebd90c7c0bff@x18g2000yqe.googlegroups.com> <42cafbad-c3aa-4aa4-a675-d0bb01fb1775@f18g2000yqd.googlegroups.com> Message-ID: On Feb 13, 8:17?am, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, ecu_jon wrote: > > > > > i just tried changing that in ver12a, still get > > IOError: [Errno 2] No such file or directory: 'V:\\week2\\configs\ > > \apache2.conf' > > good catch tho as that is needed. thanks. > > weekchoice is used to pick week 1-4. really jsut returns 1-4. i plan > > to do full weekly backups with another script. > > getusername i was using when i was trying to build the path as part of > > a unc path. isdir/isfile did not play well with that. > > homedir returns the users home directory. works in xp,7, and linux. > > source and destination should be self explanatory. > > the backupall() gets called from clicking the button. for now its the > > meat and potatoes im working on. it is trying to recursively copy > > files/folders from source to dest. the for ... os.walk line digs > > through the backup folder. i use os.chgdir , os.getcwd and leftover to > > build the path for file/folder names on dest. basically start at c: > > \users\name\backup\somefolder and end with just somefolderadded to > > dest. > > if os.path.isdir(fname): checks if it is a folder. copytree is a > > recursive folder ?copy. > > elif os.path.isfile(fname): if it is a file. copy2 copies files and > > metadata. > > class MyForm(wx.Frame): and down is wxpython, that works. ( tho i will > > take suggestions but i know this is not the right forum to as > > questions for that part) > > I haven't tried to run your script, since much of it is Windows > dependent, and I'm on Linux. ?So observations are just by inspection. > > I suspect your problem is that you're trying to change drives as well as > directories. ?In Windows, there's a current directory on each drive, > that Windows remembers. ?So changing directories on a different drive > doesn't mean what you might think it does. ?I'd recommend doing no > chdir()'s at all, and using only absolute paths. > > But I see other complications or maybe risks in the code, concentrating > on function ?backupall(). ?You're using os.walk(), which walks through a > whole tree of files. ?But then when you encounter a directory, you're > doing a copytree(). ?So you'll be copying the same files many-many times. > > Similarly, you have logic for copying a single file, but you invoke it > on a name from dirlist, which is a list of directories, so the isfile() > probably never fires. > > os.walk() assumes the current directory is unchanged during its run. > See: ?http://docs.python.org/library/os.html#module-os > ? ?"walk() never changes the current directory, and assumes that its > caller doesn?t either." > > You're not copying the files at the top level at all; ?you don't process > the list called 'files', while you could probably safely copy *only* the > files. > > Your name manipulations in this same function look risky, using replace > when you presumably know that a string is either at the begin or end. > > In function homeDir(), you never return the value calculated in the try > block. ?If you don't get an exception, you return None. > > DaveA first let me say, you guys are helping me and i thank you for that. i do not want to sound confrontational. i have don my best to make this os agnostic. yes i know, right now in 21a, destination2 is windows specific. that's mostly because os.path.isdir() and unc paths do not play well with each other. the os.chdir() came about out of need to build relative path names. some examples : c:\users\name\backup\ #win7 c:\docs and settings\name\app data\backup\ #winxp /home/name/backup #linux and mac i wanted to start from 'backup' in all these cases. my destination is going to look like \\servername\username\week[1-4] yes os.walk goes thru the whole tree (under backup in my case). the os.chdir() under the for line in def backupall(): basically juct chages folders to whever the os.walk() is. it never tried to change to a different drive letter.the folder copy thing, these 2 lines if os.path.isdir(fname): #if it is a folder if not os.path.isdir(destination+leftover): #and id dont exist on dest drive work on version 011, determine if its a folder, then if it exists. only copy if both: it is a folder, and not exist on destination. this "return homedir" needed to be moved 1 tab left. copy error from random code to functionalizing parts. good catch thanks. dirlsit, returns the names of folders and files. i was using a different method http://thanksforallthefish.endofinternet.net/date-linuxversion.py try version 11 for yourself. in your home directory (ie: /home/name) make a backup folder, put a few files/folders in it. then make a backup2 folder, and make week1,week2week3week4 folders. version 11 will copy the top level files under /home/name/backup , and recreate the directory structure. so "You're not copying the files at the top level at all; you don't process the list called 'files', while you could probably safely copy *only* the files. " atleats for version 11 is not true. atleast not within the bounds i have tested it. "Your name manipulations in this same function look risky, using replace when you presumably know that a string is either at the begin or end. " i know. i have several things that need to build up. like starting from a relative position and going to a different position. username would be part of the unc path if i could get that to work, and week[1-4] is part of the name. the thing that gets me is version 11 works. well. but its is reading/ writing to almost the same place (from backup, to backup2). defiantly open to suggestions. From piet at vanoostrum.org Sun Feb 13 13:40:09 2011 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sun, 13 Feb 2011 14:40:09 -0400 Subject: Which non SQL Database ? References: Message-ID: For non-SQL you could look into Kyoto Cabinet, which is Berkeley DB-like. Or ZODB which is a Python Object databes. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From clp2 at rebertia.com Sun Feb 13 13:43:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 13 Feb 2011 10:43:59 -0800 Subject: How can I print a traceback without raising an exception? In-Reply-To: References: Message-ID: On Sun, Feb 13, 2011 at 10:05 AM, Gerald Britton wrote: > In the following example, I raise an exception in function h() which > prints a traceback. ?I would like to know how I can get a similar > display on my terminal without raising an exception. ?That is, can I > replace "raise Exception" in function h() with some sequence of > instructions (possibly using the inspect module) that will generate a > similar call trace ?of how I got to that point? > > Example: > >>>> def f(): > ... ?g() > ... >>>> def g(): > ... ?h() > ... >>>> def h(): > ... ?raise Exception ?# Replace with something to generate a call trace > ... >>>> f() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 2, in f > ?File "", line 2, in g > ?File "", line 2, in h > Exception >>>> traceback.print_stack(): http://docs.python.org/library/traceback.html#traceback.print_stack Cheers, Chris From hayesjdno3 at yahoo.com Sun Feb 13 13:58:23 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 10:58:23 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Please don't dump code on us and tell us to ignore parts of it. We're offering our time and experience without charging you, the least you can do is take the time to eliminate the irrelevant parts of the code yourself, and show us the smallest piece of code which demonstrates the problem. " i appreciate your opinion. im fairly new here so i might not get etiquette right.i only asked you all to ignore it for 2 reasons, it's wxpython to not really targets to the crowd, and it does not interact with the python parts. other than simply as a means to call the functions. i could chop off the bottom and replace it with a functname(), it would be the same for my question. i know backslashes are special. there a special pain in my #$%. without a windows environment, you would have to change destination2 significantly to try it out. but like i said above you can try version 11 in a linux environment. i know config does not exist, for some reason the isfolder check is passing it off saying it exists, when it does not. then moving on to the isfiles parts. tries to copy a folder deep files with no folder to write to, and fails. i jsut don't understand why the folder check is not working right in version 12a. and destination2, IS basically the difference between 11 and 12a. it should be the only difference. the isfile difference someone else pointed out i have since changed that, stil lsame problem. and again thanks all for time/trouble. From rantingrick at gmail.com Sun Feb 13 14:18:39 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 11:18:39 -0800 (PST) Subject: Call to Update All Tutorials to Python3.x Standards. Message-ID: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> We need to start demanding that folks move towards 3.0 compliance with their tutorials. Most of the functionality in Python3000 is available from the __future__ module, especially in Python2.6 and up. There is no reason to continue supporting deprecated tutorials. If someone is still using an very old version of Python then they should learn from the official tutorial. However just ignoring the currently outdated tutorials is NOT enough, we must modify them or destroy them. This is the only way we can guarantee that confusion is not propagated through the ranks of new users. We must reign in this multiplicity and we must move forward in our evolution. Some folks will need to be brought into compliance kicking and screaming... so be it! If they are not willing to move forward then we must demand that they annotate their tutorials as OUT OF DATE with very prominent warnings. These annotations need to exists on every page and everywhere a new feature has superseded an old feature. Also it would also be wise to include a link to the relevant part of the official tutorial that showcases the new syntax/functionality. Like for instance the print function, string formatting, etc, etc. If any tutorial owners refuse to cooperate we need to remove their tutorials (and/or links to their tutorials) from the official Python website forever. We must not be a party to multiplicity. We must stand united to move the Python code base forward and into 3.0 compliance. You can always read the official tutorial of an old version if you need to, but we cannot allow confusion to exists on the internet. This will be a painful blow to some, but progress is far more important than any one persons "feelings" getting hurt. We must move forward, and if that means leaving some selfish folks behind THEN SO BE IT! From rantingrick at gmail.com Sun Feb 13 15:13:14 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 12:13:14 -0800 (PST) Subject: Call to Update All Tutorials to Python3.x Standards. References: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> Message-ID: <9785792a-d215-4b65-b719-36fefbd9e3b2@x4g2000prf.googlegroups.com> PS: ------------------ Open Invitation: ------------------ I am more than willing to help out those who need to bring Python2.x tutorials into 3.x compliance (and i invite others to get involved!). I would prefer to convert all to 3.x tutorials and not engage in "monkey patching" by annotating the deprecations. But either way i am willing to help as long as we are moving forward as a community. If you are a tutorial owner and would like to be a part of Python's future and not simply a landscaper of some rotting historical landmark of "days gone by, then contact me either on list or off so we can discuss the evolution of your tutorial, and the evolution of your students minds. Together we shall be a part of the solution and not a part of the problem. Thank You. From tyler at tysdomain.com Sun Feb 13 15:52:48 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 13 Feb 2011 13:52:48 -0700 Subject: Call to Update All Tutorials to Python3.x Standards. In-Reply-To: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> References: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> Message-ID: <4D5844A0.3080400@tysdomain.com> Hahaha. You've got a new one every week, don't you. What happened to the demand to evolve idol into the future or whatever the BS you were parroting was? So we're on TKInter being fixed/replaced, (which you haven't worked with the steps people gave you), Idol being forked and redone, (again which you haven't done), and now you want to drag people "kicking and screaming" into tutorial updates. Well, at least you provide for some amusement, anyway. What's the bet RR will be demanding GV step up? And I'm sure he's got the silent majority, yet again. From tshinnic at io.com Sun Feb 13 16:03:18 2011 From: tshinnic at io.com (Thomas L. Shinnick) Date: Sun, 13 Feb 2011 15:03:18 -0600 Subject: Call to Update All Tutorials to Python3.x Standards. In-Reply-To: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegro ups.com> References: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> Message-ID: At 01:18 PM 2/13/2011, rantingrick wrote: >If any tutorial owners refuse to cooperate we need to remove their >tutorials (and/or links to their tutorials) from the official Python >website forever. How many tutorials have you written? In a city I used to live in, a long while ago, ... You would stop at a red light at a downtown corner and some unkempt fellow would lurch out of nowhere, stagger onto your hood, smear his dirty rag over a part of your windshield once or twice, rock back on his heels unsteadily, and thrust out his hand towards the car window. You could react in different ways. If you disdained to acknowledge his specific service to your general good he would start yelling at the top of his lungs at what an ingrate you were, that you should *appreciate* that he had /cleaned/ your windshield (though more smeared now than before), that you were too stupid to know you were now in a better situation than before he had arrived, and beckoning to his fellow corner bums (who quite ignored the blowhard's umpteenth snit that day) and any passersby (who scurried away fast as they could) that all should upbraid you for the lackwit that you were. At length, for as long as there was an audience. Others would point to the smeared windshield and start screaming he'd dirtied their windshield, made it worse than before, he was a bum, he needed to get a job, etc. etc. To which he would respond, well, just as above, except adding that they were obviously blind or unbalanced. Others would pantomime not having any money to give him for his service, so sorry. To which he would respond, well, as above, except adding that they were liars and cheats, and at least he was an honest bum. Some would drive off chancing against knocking the fellow down, worried he would then scream for the police to arrest them for hit and run. Others would freeze, until a half-dozen car horns on a green light would release them from their quandary. And of course some would give him money, or throw it at him, and thus rewarding his dirty deeds. And his fellow bums shuffled off to some other street corner with a stop light and tried the same scam themselves. This went on for over a year. You see, there were the people who said that the bums were really trying to help people, improve the general good. And who would say that the bums didn't have the resources to keep their rags clean, so the dirtied windshields couldn't be helped. And what's wrong with trying to do good things? But with more traffic stoppages at more and more downtown corners, this bit of tramp theatre became less droll by the day. And then the business people noticed customers were avoiding the downtown. And then the ragged crew spread out from downtown. And then a couple of high society pooh-poohing do-gooders had the exact same joyful encounter, and poo-pooed badly. I'd like to say the solution was simple, and that the city passed some regulations, and the police were given a directive to stop overlooking all this, and the practice stopped. Well, it was, and did, and were, and it did. But then the desperate, in the afternoon or evening when the lack of recent drink was most pressing, would lurch out from a corner and throw themselves on a slowed and turning car, bounce (less than balletically) off, wailing and moaning at how'd they'd been most severely injured by the driver's gross and unconscionable negligence and blindness, their licenses should be taken away, jailed, call an ambulance, etc. Not so strangely, this worked a treat, especially if the driver hadn't seen it coming. (Though sometimes the accident took a lot of work on the bum's end - I saw one get "run over" by a car, half a block from where the bum ran out onto the street, on the other side of the street, with the car now reversing - it didn't help if you could see it coming) And better, you didn't even have to have a rag. You only had two options, pay up or call his bluff and call the police. People paid, and found themselves having 'hit' perhaps the very same bum a couple weeks later. Call the police and the bum would be gone before they got there, having screamed and muttered imaginative 'compliments' in your direction all the while shambling off. I think the city ended up having to strengthen the regulations, and simply started locking up all the bums. I don't really remember though, because I stopped going downtown and eventually left the city entirely. Rick, you're using the same rag now for weeks. It's dirty. Quit being the rag man. It won't get you the drink you want. It will only make you "rag man rick". From bjracine at glosten.com Sun Feb 13 16:17:55 2011 From: bjracine at glosten.com (Benjamin J. Racine) Date: Sun, 13 Feb 2011 13:17:55 -0800 Subject: Extending classes __init__behavior for newbies Message-ID: I don't quite understand the interplay of the two different __init__ methods when trying to extend a class. Below is my hack attempt at doing so... class ship(object): def __init__(self,l=0,b=0,t=0,name=''): self.l = l self.b = b self.t = t self.name = name def make_it_deeper(self,t): self.t = self.t - t class fast_ship(ship): def __init__(self,speed = 0): self.speed = speed my_ship = fast_ship(l = 100,b = 50, t = 10, name = 'cutter',speed = 10) If anyone would be so kind as to show me how to get the intended effect that I've hinted at, I would be most grateful, Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun Feb 13 16:41:38 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 13:41:38 -0800 (PST) Subject: Call to Update All Tutorials to Python3.x Standards. References: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> Message-ID: On Feb 13, 3:03?pm, "Thomas L. Shinnick" wrote: > > In a city I used to live in, a long while ago, ... > > You would stop at a red light at a downtown corner and some unkempt > fellow would lurch out of nowhere, stagger onto your hood, smear his > dirty rag over a part of your windshield once or twice, rock back on > his heels unsteadily, and thrust out his hand towards the car window. Sadly this the case in many cities world wide. And what is the cause of this infestation? Bloated and overbearing government bureaucracies killing the soul of it's citizens! When you over tax citizens... they leave. When create asinine laws that make running a buisness almost impossible... they leave too. Likewise when you create housing projects... who stays? Likewise when you create a welfare mentality... who stays? However soon you find yourself in a giant conundrum... When you push out the tax payers and you propagate selfishness within your populace, who then will you steal the money from to maintain your house of cards? How then will you divert their attention from the wee little man behind the curtain pulling levers making lots of smoke and noise but not much else? This is how civilizations fall on a grand scale. Look at every major city around the world and you'll see why we find ourselves in the global recession. SELFISHNESS, CORRUPTION, and GREED. Those are the only types of folks left in the cities; the selfish, the corrupt, and the greedy. The honest folks got the hell out before it collapsed into chaos. Coming soon to a big city near you... devolution! (psst: this may include the Python community too!) > How many tutorials have you written? Your attempts to connect me to the bums are laughable. I am the only person publicly calling for change, for self responsibility, and for a *real* community with a united vision of the future. Anybody that argues for keeping old incompatible 2.x tutorials is just a historical landscaper plain and simple. That's fine. If you wish to live in the past be my quest. However *we* are going to move forward with or without you. From prologic at shortcircuit.net.au Sun Feb 13 17:00:19 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 14 Feb 2011 08:00:19 +1000 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: Message-ID: On Mon, Feb 14, 2011 at 7:17 AM, Benjamin J. Racine wrote: > I don't quite understand the interplay of the two different __init__ methods > when trying to extend a class. ?Below is my hack attempt at doing so... > class ship(object): > ?? ?def __init__(self,l=0,b=0,t=0,name=''): > ?? ? ?self.l = l > ?? ? ? ?self.b = b > ?? ? ? ?self.t = t > ?? ? ? ?self.name = name > ?? ?def make_it_deeper(self,t): > ?? ? ? ?self.t = self.t - t > class fast_ship(ship): > ?? ?def __init__(self,speed = 0): > ?? ? ? ?self.speed = speed > my_ship = fast_ship(l = 100,b = 50, t = 10, name = 'cutter',speed = 10) > > If anyone would be so kind as to show me how to get the intended effect that > I've hinted at, I would be most grateful, When you subclass a base class (ship in your example) you need to call it's parent (or super) methods. This includes the constructor (__init__). The standard way of doing this in Python is: class FasterShip(Ship): def __init__(self, l=0,b=0,t=0,name='', speed=0): super(FasterShip, self).__init__(l, b, t, name) self.speed = speed This ensures that the constructor of the base class (Ship) gets called and the object initialized with the attributes you've defined. Note for convention reasons I've also included proper class names in the example. Classes normally start with an Upper case letter. cheers James -- -- James Mills -- -- "Problems are solved by method" From tyler at tysdomain.com Sun Feb 13 17:03:12 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Sun, 13 Feb 2011 15:03:12 -0700 Subject: Call to Update All Tutorials to Python3.x Standards. In-Reply-To: References: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> Message-ID: <4D585520.7020404@tysdomain.com> >However *we* are going to move forward with or >without you. In other words: We in RR's book means RR and this silent majority that has pitched in so much work to back his last call to move forward, that we're now boggling in awe at a new Idol. And moving forward means posting lots of trash, (he calls this speaking up), reverting to insults when people don't back him in his crusade to move us forward, (he calls this vision and pursuasion), then hoping that it all holds up. When a solution is posed, he goes quiet, (this again I guess is called evolution), until he can find something else to complain about, and the last complaints are left by the wayside. From timr at probo.com Sun Feb 13 17:11:23 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 13 Feb 2011 14:11:23 -0800 Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: ecu_jon wrote: > >i know backslashes are special. there a special pain in my #$%. >without a windows environment, you would have to change destination2 >significantly to try it out. but like i said above you can try version >11 in a linux environment. If they are a pain in your #$%, then don't use them. You can use forward slashes everywhere in Windows, except when typing commands at the command prompt. ALL of the Windows file system APIs accept forward slashes. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Sun Feb 13 17:21:56 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 13 Feb 2011 22:21:56 +0000 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: Message-ID: <4D585984.60303@mrabarnett.plus.com> On 13/02/2011 22:00, James Mills wrote: > On Mon, Feb 14, 2011 at 7:17 AM, Benjamin J. Racine > wrote: >> I don't quite understand the interplay of the two different __init__ methods >> when trying to extend a class. Below is my hack attempt at doing so... >> class ship(object): >> def __init__(self,l=0,b=0,t=0,name=''): >> self.l = l >> self.b = b >> self.t = t >> self.name = name >> def make_it_deeper(self,t): >> self.t = self.t - t >> class fast_ship(ship): >> def __init__(self,speed = 0): >> self.speed = speed >> my_ship = fast_ship(l = 100,b = 50, t = 10, name = 'cutter',speed = 10) >> >> If anyone would be so kind as to show me how to get the intended effect that >> I've hinted at, I would be most grateful, > > When you subclass a base class (ship in your example) you need > to call it's parent (or super) methods. This includes the constructor > (__init__). > > The standard way of doing this in Python is: > > class FasterShip(Ship): > > def __init__(self, l=0,b=0,t=0,name='', speed=0): > super(FasterShip, self).__init__(l, b, t, name) > > self.speed = speed > > This ensures that the constructor of the base class (Ship) gets called > and the object initialized with the attributes you've defined. > > Note for convention reasons I've also included proper class names > in the example. Classes normally start with an Upper case letter. > I would've done it this way: class FasterShip(Ship): def __init__(self, speed=0, **kwargs): Ship.__init__(self, **kwargs) self.speed = speed From timr at probo.com Sun Feb 13 17:23:40 2011 From: timr at probo.com (Tim Roberts) Date: Sun, 13 Feb 2011 14:23:40 -0800 Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> Message-ID: <17mgl6pjtet543p47o35evdf86s7s5nj6i@4ax.com> ecu_jon wrote: >i have a samba server at home (acting as my test environment) with one >of the 'shares' mounted as v: on my windows box. inside of that are 4 >folders week[1-4]. i have created c:\users\name\backup , and put a few >files/folders in there to test with. please ignore the wxpython parts >of the script, the last 1/3, that part is functional. initial test was >looking good. (in the code, ver011 source1, destination1) coping files/ >folders and not clobbering files. going to version 12a, it seems like >it is trying to copy the files under the folder, before making the >folder. Where do you think your code is creating the folder? I don't see that happening anywhere. I also don't understand why you are doing another os.listdir(). Everything you need is already being supplied to you by the os.walk, and it is taking the extra step of separating the directories and the files automatically. Why can't you just iterate through "dirs" creating your subdirectories, and then iterate through "files" doing the copies? Then, when os.walk calls you with the files in the subdirectories, you'll know those directories already exist. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rantingrick at gmail.com Sun Feb 13 17:25:07 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 14:25:07 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: Message-ID: <7999ef82-9ffb-4671-bd9a-5177f5542fcb@8g2000prt.googlegroups.com> On Feb 13, 4:00?pm, James Mills wrote: [snip] > When you subclass a base class (ship in your example) you need > to call it's parent (or super) methods. This includes the constructor > (__init__). > > The standard way of doing this in Python is: > > class FasterShip(Ship): > > ? ? def __init__(self, l=0,b=0,t=0,name='', speed=0): > ? ? ? ? super(FasterShip, self).__init__(l, b, t, name) Is super really necessary here James? I think the use of super in this manner is just as confusing to noobs as using map/filter are to list comprehensions/generators. However in exactly the opposite "syntactical" way since dumping super reduces syntax. Not trying to pick on you, just curious. From prologic at shortcircuit.net.au Sun Feb 13 17:27:10 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 14 Feb 2011 08:27:10 +1000 Subject: Extending classes __init__behavior for newbies In-Reply-To: <4D585984.60303@mrabarnett.plus.com> References: <4D585984.60303@mrabarnett.plus.com> Message-ID: On Mon, Feb 14, 2011 at 8:21 AM, MRAB wrote: > I would've done it this way: > > class FasterShip(Ship): > ? ?def __init__(self, speed=0, **kwargs): > ? ? ? ?Ship.__init__(self, **kwargs) > ? ? ? ?self.speed = speed What's the difference between calling the base class's constructor directly and using the super type ? cheers James -- -- James Mills -- -- "Problems are solved by method" From rantingrick at gmail.com Sun Feb 13 17:29:14 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 14:29:14 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: Message-ID: On Feb 13, 4:21?pm, MRAB wrote: > I would've done it this way: > > class FasterShip(Ship): > ? ? ?def __init__(self, speed=0, **kwargs): > ? ? ? ? ?Ship.__init__(self, **kwargs) > ? ? ? ? ?self.speed = speed Well it seem MRAB and i actually agree on *one* thing. Well, when they said... "great minds think alike" ...they never mentioned *anything* about frequency. ;-) From steve+comp.lang.python at pearwood.info Sun Feb 13 17:30:55 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Feb 2011 22:30:55 GMT Subject: Call to Update All Tutorials to Python3.x Standards. References: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> Message-ID: <4d585b9f$0$29967$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Feb 2011 15:03:18 -0600, Thomas L. Shinnick wrote: > At 01:18 PM 2/13/2011, rantingrick wrote: >>If any tutorial owners refuse to cooperate we need to remove their >>tutorials (and/or links to their tutorials) from the official Python >>website forever. > > How many tutorials have you written? > > In a city I used to live in, a long while ago, ... [...] As entertaining as the story was, please don't give the troll the attention he craves. If we ignore him, and refuse to respond to his ravings, maybe he'll move on. The official stance of the Python development team is that 2.7 and 3.x will co-exist for a long, long time. Removing 2.x tutorials would be cutting off our nose to spite our face. -- Steven From rantingrick at gmail.com Sun Feb 13 17:32:09 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 14:32:09 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> Message-ID: <6b392d63-d6a6-48d2-a0fd-63a8f4f3e8de@v31g2000vbs.googlegroups.com> On Feb 13, 4:27?pm, James Mills wrote: > > class FasterShip(Ship): > > ? ?def __init__(self, speed=0, **kwargs): > > ? ? ? ?Ship.__init__(self, **kwargs) > > ? ? ? ?self.speed = speed > > What's the difference between calling the base > class's constructor directly and using the super type ? well for starters... * confusion and clarity * liberal and conservative * excess and moderation ... just to name a few. From steve+comp.lang.python at pearwood.info Sun Feb 13 17:37:48 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Feb 2011 22:37:48 GMT Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d585d3c$0$29967$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Feb 2011 10:58:23 -0800, ecu_jon wrote: > i know config does not exist, for some reason the isfolder check is > passing it off saying it exists, when it does not. [steve at sylar ~]$ grep isfolder facbac-011.py [steve at sylar ~]$ grep isfolder facbac-012a.py [steve at sylar ~]$ There is no such "isfolder" check in your source code. -- Steven From rantingrick at gmail.com Sun Feb 13 17:39:45 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 14:39:45 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: Message-ID: <786c90bb-075e-4316-a3c1-563d13919a7f@k16g2000vbq.googlegroups.com> On Feb 13, 4:00?pm, James Mills wrote: > class FasterShip(Ship): > > ? ? def __init__(self, l=0,b=0,t=0,name='', speed=0): > ? ? ? ? super(FasterShip, self).__init__(l, b, t, name) > > ? ? ? ? self.speed = speed Did everyone miss the fact that this inheritance is unnecessary? Considering the Ship class has an attribute "speed" that will be affected (either directly or indirectly) by simply modifying it? faster_ship = Ship() faster_ship.speed = someFasterSpeed From benjamin.kaplan at case.edu Sun Feb 13 17:42:31 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 13 Feb 2011 17:42:31 -0500 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: <4D585984.60303@mrabarnett.plus.com> Message-ID: On Feb 13, 2011 5:37 PM, "James Mills" wrote: > > On Mon, Feb 14, 2011 at 8:21 AM, MRAB wrote: > > I would've done it this way: > > > > class FasterShip(Ship): > > def __init__(self, speed=0, **kwargs): > > Ship.__init__(self, **kwargs) > > self.speed = speed > > What's the difference between calling the base > class's constructor directly and using the super type ? > > cheers > James > > -- In this case, nothing. If you use multiple inheritance and you end up with weird inheritance heirarchies, super might not return the class you think it will return. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Sun Feb 13 17:47:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 14:47:53 -0800 (PST) Subject: Call to Update All Tutorials to Python3.x Standards. References: <867e526d-6431-46cf-9054-af8d1132596f@y31g2000prd.googlegroups.com> <4d585b9f$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 13, 4:30?pm, Steven D'Aprano wrote: > The official stance of the Python development team is that 2.7 and 3.x > will co-exist for a long, long time. Removing 2.x tutorials would be > cutting off our nose to spite our face. That is BS Steven and you know it! Of course we are going to support 2.x for a long, long, time. Heck we even have downloads available for Python1.x. I am talking about TUTORIALS steven, TUTORIALS! However we should NOT be proliferating confusion by allowing 2.x and 3.x TUTORIALS to exists in the wild. I have tons of code that is written in 2.x and non compatible for 3.x. However if i don't start writing 3.x code soon, in the future i will have tons, and tons, and tons, of code that is not 3.x compatible. Stop spreading lies Steven. We are going to support 2.x because people have code bases that would be too painful to change over now. HOWEVER! We must encourage any NEW code to be written in 3.x compatible style. PS: The only troll here is YOU! PPS: I am talking about TUTORIALS! From steve+comp.lang.python at pearwood.info Sun Feb 13 18:01:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Feb 2011 23:01:02 GMT Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> Message-ID: <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Feb 2011 08:27:10 +1000, James Mills wrote: > On Mon, Feb 14, 2011 at 8:21 AM, MRAB > wrote: >> I would've done it this way: >> >> class FasterShip(Ship): >> ? ?def __init__(self, speed=0, **kwargs): >> ? ? ? ?Ship.__init__(self, **kwargs) >> ? ? ? ?self.speed = speed > > What's the difference between calling the base class's constructor > directly and using the super type ? If you have *only* single inheritance, then there is no practical difference and no harm in using super(). If you have multiple inheritance, then you *must* use super(), otherwise your method will not correctly call all the superclasses that it needs to. -- Steven From hayesjdno3 at yahoo.com Sun Feb 13 18:01:25 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 15:01:25 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 13, 5:11?pm, Tim Roberts wrote: > ecu_jon wrote: > > >i know backslashes are special. there a special pain in my #$%. > >without a windows environment, you would have to change destination2 > >significantly to try it out. but like i said above you can try version > >11 in a linux environment. > > If they are a pain in your #$%, then don't use them. ?You can use forward > slashes everywhere in Windows, except when typing commands at the command > prompt. ?ALL of the Windows file system APIs accept forward slashes. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. can you give an example of how to build a folder name, maybe as a string, with parts of it as variables, that have to be strung together. like x = "//servername/+variable+"/"+variable+"/" when i did something liek that the end result string was like //servername/folder/folder\file and i got an error From prologic at shortcircuit.net.au Sun Feb 13 18:11:47 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Mon, 14 Feb 2011 09:11:47 +1000 Subject: Extending classes __init__behavior for newbies In-Reply-To: <786c90bb-075e-4316-a3c1-563d13919a7f@k16g2000vbq.googlegroups.com> References: <786c90bb-075e-4316-a3c1-563d13919a7f@k16g2000vbq.googlegroups.com> Message-ID: On Mon, Feb 14, 2011 at 8:39 AM, rantingrick wrote: > Did everyone miss the fact that this inheritance is unnecessary? > Considering the Ship class has an attribute "speed" that will be > affected (either directly or indirectly) by simply modifying it? The attribute "speed" was not a member of the OP's class ship. cheers James -- -- James Mills -- -- "Problems are solved by method" From rantingrick at gmail.com Sun Feb 13 18:12:00 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 15:12:00 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 13, 5:01?pm, Steven D'Aprano wrote: > On Mon, 14 Feb 2011 08:27:10 +1000, James Mills wrote: > > What's the difference between calling the base class's constructor > > directly and using the super type ? > > If you have *only* single inheritance, then there is no practical > difference and no harm in using super(). False! There IS harm in using super when super not needed. The difference is readability! And don't downplay that aspect. You yourself have said this in the past. It seems *some* of us have very short memories. > If you have multiple inheritance, then you *must* use super(), otherwise > your method will not correctly call all the superclasses that it needs to. True! You must you super in this case or in any case where you DO NOT know the identifier of the base class. However the point is: NEVER USE SUPER UNLESS YOU ABSOLUTELY HAVE NO OTHER OPTION! From askutt at gmail.com Sun Feb 13 18:14:30 2011 From: askutt at gmail.com (Adam Skutt) Date: Sun, 13 Feb 2011 15:14:30 -0800 (PST) Subject: multiprocessing & more References: Message-ID: <373ecdcf-bb97-4f90-b291-03993fb97ce6@x11g2000yqc.googlegroups.com> On Feb 13, 12:34?pm, Andrea Crotti wrote: > > First of all, does it make sense to use multiprocessing and a short > value as boolean to check if the simulation is over or not? > Maybe, but without knowing exactly what you're doing it's difficult to say if any other approach would be superior. Plus, most of the other approaches I can think of would require code modifications or platform- specific assumptions. > > As last thing to know when to start to analyze the data I thought about this > > ? ? ? ? while len(listdir(res_dir)) < len(network): > ? ? ? ? ? ? sleep(0.2) > > which in theory it should be correct, when there are enough files as > the number of nodes in the network everything should be written. ?BUT > once every 5 times I get an error, telling me one file doens't exists. > > That means that for listdir the file is already there but trying to > access to it gives error, how is that possible? File I/O is inherently a concurrent, unsynchronized activity. A directory listing can become stale at any time, even while the directory listing is being built (e.g., imagine running ls or dir in a directory where rm or del is currently executing). When a directory is being modified while you're listing it, the contents of the listing essentially become "undefined": you may get entries for files that no longer exist, and you may not get entries for that do exist. A directory listing may also return duplicate entries; this is what I expect is happening to you. The right thing to do is actually check to see if all the files you want exist, if you can. If not, you'll have to keep waiting until you've opened all the files you expect to open. Adam From ben+python at benfinney.id.au Sun Feb 13 18:15:06 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Feb 2011 10:15:06 +1100 Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zkpzil1h.fsf@benfinney.id.au> Tim Roberts writes: > ecu_jon wrote: > > > >i know backslashes are special. there a special pain in my #$%. > >without a windows environment, you would have to change destination2 > >significantly to try it out. but like i said above you can try > >version 11 in a linux environment. > > If they are a pain in your #$%, then don't use them. You can use > forward slashes everywhere in Windows, except when typing commands at > the command prompt. ALL of the Windows file system APIs accept forward > slashes. Even better: Don't manually handle the path component separator at all, and use ?os.path.join? to do it correctly. That's exactly what it's there for. -- \ ?We tend to scoff at the beliefs of the ancients. But we can't | `\ scoff at them personally, to their faces, and this is what | _o__) annoys me.? ?Jack Handey | Ben Finney From mdekauwe at gmail.com Sun Feb 13 18:16:30 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sun, 13 Feb 2011 15:16:30 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> Message-ID: <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> On Feb 13, 6:35?pm, Terry Reedy wrote: > On 2/12/2011 9:20 PM, Martin De Kauwe wrote: > > > On Feb 13, 5:12 am, Terry Reedy ?wrote: > >> On 2/12/2011 1:24 AM, Martin De Kauwe wrote: > > >>> The point of this posting was just to ask those that know, whether it > >>> was a bad idea to use the class object in the way I had or was that > >>> OK? And if I should have just used a dictionary, why? > > >> Did you miss my suggestion to use a module rather than a class? > >> Modules do not have some of the disadvantages of classes listed by J. Nagle. > > >> -- > >> Terry Jan Reedy > > > Hi, sorry I did. I just re-read it, could you provide an example? > > I am not sure what you are asking. tkinter.contants is one example. > > > Sorry i am having a major mind blank this morning (I think this is > > obvious!?). And it would meet all of the criteria outlined by John > > Nagle? > > A module will work fine if but only if you commit yourself to having all > keys be legal Python identifiers. But that is usually not a problem with > configuration values. > > -- > Terry Jan Reedy I think I got it, did you mean something like this? class Constants: radius_of_earth = 6.37122E+6 days_as_yrs = 1.0 / 365.25 m2_as_ha = 1E-4 # metres squared as hectares g_as_tonnes = 1E-6 # grammes as tonnes kg_as_tonnes = 1E-3 # kg as tonnes kg_as_g = 1E+3 def __init__(self): self.radius_of_earth = self.__class__.radius_of_earth self.days_as_yrs = self.__class__.days_as_yrs self.m2_as_ha = self.__class__.m2_as_ha self.g_as_tonnes = self.__class__.g_as_tonnes self.kg_as_tonnes = self.__class__.kg_as_tonnes self.kg_as_g = self.__class__.kg_as_g usage something like >>>from constants import Constants >>>Constants.kg_as_g >>>1000.0 Something similar for the params? thanks From ben+python at benfinney.id.au Sun Feb 13 18:19:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Feb 2011 10:19:44 +1100 Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> Message-ID: <87vd0niktr.fsf@benfinney.id.au> James Mills writes: > On Mon, Feb 14, 2011 at 8:21 AM, MRAB wrote: > > I would've done it this way: > > > > class FasterShip(Ship): > > ? ?def __init__(self, speed=0, **kwargs): > > ? ? ? ?Ship.__init__(self, **kwargs) > > ? ? ? ?self.speed = speed > > What's the difference between calling the base > class's constructor directly and using the super type ? The difference arises in multiple inheritance. Your class can never know whether it is used as part of a multiple-inheritance hierarchy, in which case calling the base class directly would be the wrong thing to do since that might not match the MRO. However, using ?__super__? properly is very problematic. A case can be made that it's an inherent problem of multiple inheritance, which should therefore be avoided. Search the archives of this forum to learn more. -- \ ?If you don't know what your program is supposed to do, you'd | `\ better not start writing it.? ?Edsger W. Dijkstra | _o__) | Ben Finney From rantingrick at gmail.com Sun Feb 13 18:24:34 2011 From: rantingrick at gmail.com (rantingrick) Date: Sun, 13 Feb 2011 15:24:34 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <786c90bb-075e-4316-a3c1-563d13919a7f@k16g2000vbq.googlegroups.com> Message-ID: On Feb 13, 5:11?pm, James Mills wrote: > On Mon, Feb 14, 2011 at 8:39 AM, rantingrick wrote: > > Did everyone miss the fact that this inheritance is unnecessary? > > Considering the Ship class has an attribute "speed" that will be > > affected (either directly or indirectly) by simply modifying it? > > The attribute "speed" was not a member of the > OP's class ship. My solution still stands... >>> class Ship(object): pass >>> faster_ship = Ship() >>> faster_ship.speed = 10 ...if the creation of instance variable "speed" is all that is needed then the inheritance is still unnecessary. Since "speed" did not exist in the base, then one can reason that no method of Ship could have modified "speed" as that modification would raise an attribute error UNLESS Ship is an ABC! OR Unless the OP creates *some* instance method of FasterShip that operates on the instance variable "speed" it would be redundant to use inheritance. However if an instance method of FasterShip required the instance variable "speed" then we have reason for inheritance. So true if Ship is an ABC or if any FasterShip method requires a "speed" instance variable. From ben+python at benfinney.id.au Sun Feb 13 18:36:57 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Feb 2011 10:36:57 +1100 Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <87vd0niktr.fsf@benfinney.id.au> Message-ID: <87r5bbik12.fsf@benfinney.id.au> Ben Finney writes: > However, using ?__super__? properly is very problematic. By which I meant the ?super? built-in. Sorry for any resulting confusion. -- \ ?Pinky, are you pondering what I'm pondering?? ?Uh, I think so, | `\ Brain, but balancing a family and a career ... ooh, it's all | _o__) too much for me.? ?_Pinky and The Brain_ | Ben Finney From ben+python at benfinney.id.au Sun Feb 13 18:39:43 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Feb 2011 10:39:43 +1100 Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxlzijwg.fsf@benfinney.id.au> ecu_jon writes: > can you give an example of how to build a folder name, maybe as a > string, with parts of it as variables, that have to be strung > together. like x = "//servername/+variable+"/"+variable+"/" import os.path infile_path = os.path.join(["//servername", start_dir, other_dir]) Read the documentation for ?os.path.join?. It's fundamental if you're working with filesystem paths. > when i did something liek that the end result string was like > //servername/folder/folder\file and i got an error That path should work on MS Windows. If you want us to comment on the error, you'll need to show the code here *and* the error traceback. -- \ ?If this is your first visit to the USSR, you are welcome to | `\ it.? ?hotel room, Moscow | _o__) | Ben Finney From rhodri at wildebst.demon.co.uk Sun Feb 13 18:42:06 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 13 Feb 2011 23:42:06 -0000 Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 11 Feb 2011 02:08:01 -0000, Steven D'Aprano wrote: > On Thu, 10 Feb 2011 15:48:47 +0000, Cousin Stanley wrote: > >> Steven D'Aprano wrote: >> >>> I have a tkinter application under Python 2.6 which is shows text in a >>> giant font, about twenty(?) times larger than expected. >>> >>> The fonts are set using: >>> >>> titlefont = '-Adobe-Helvetica-Bold-R-Normal-*-180-*' >>> buttonfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' >>> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' >>> .... >> >> Although I've been a linux user for several years, that type of font >> spec hurts my head .... :-) >> >> Will the more simplistic type of tuple spec not work in your tkinter >> application ? > > I don't know, but I'll give it a try. > > Nevertheless, I'd like to learn how to diagnose these sorts of font > issues. Can anyone suggest where I should start? The Linux Cookbook has a fairly comprehensible page on the X Font Names at http://dsl.org/cookbook/cookbook_20.html (The Naming of Fonts. Hmm. Paging T S Eliot...) In this case I think you're missing a hyphen. Try titlefont = '-Adobe-Helvetica-Bold-R-Normal--*-180-*' This breaks down as: Foundry: Adobe Family: Helvetica Weight: Bold Slant: Roman Proportionate Width: Normal Additional: La la, can't hear you Size in pixels: Whatever Size in points: 180 Points as far as X is concerned are 1/727.2 of an inch. Pixels would be, oh, maybe twenty times bigger? -- Rhodri James *-* Wildebeest Herder to the Masses From davea at ieee.org Sun Feb 13 18:56:59 2011 From: davea at ieee.org (Dave Angel) Date: Sun, 13 Feb 2011 18:56:59 -0500 Subject: files,folders,paths In-Reply-To: References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <9ba1d28f-6632-492d-9f96-ebd90c7c0bff@x18g2000yqe.googlegroups.com> <42cafbad-c3aa-4aa4-a675-d0bb01fb1775@f18g2000yqd.googlegroups.com> Message-ID: <4D586FCB.8050807@ieee.org> On 01/-10/-28163 02:59 PM, ecu_jon wrote: > >> > > first let me say, you guys are helping me and i thank you for that. i > do not want to sound confrontational. i have don my best to make this > os agnostic. yes i know, right now in 21a, destination2 is windows > specific. that's mostly because os.path.isdir() and unc paths do not > play well with each other. > > the os.chdir() came about out of need to build relative path names. > some examples : > c:\users\name\backup\ #win7 > c:\docs and settings\name\app data\backup\ #winxp > /home/name/backup #linux and mac In what way do those imply a need for chdir() ? What's wrong with os.path.join() ? > > i wanted to start from 'backup' in all these cases. my destination is > going to look like > \\servername\username\week[1-4] > > yes os.walk goes thru the whole tree (under backup in my case). the > os.chdir() under the for line in def backupall(): basically juct > chages folders to whever the os.walk() is. it never tried to change to > a different drive letter. And I quote from facbac-012a.py: os.chdir("v:") > the folder copy thing, these 2 lines > if os.path.isdir(fname): #if it is a folder > if not os.path.isdir(destination+leftover): #and id > dont exist on dest drive > work on version 011, determine if its a folder, then if it exists. > only copy if both: it is a folder, and not exist on destination. > this "return homedir" needed to be moved 1 tab left. copy error from > random code to functionalizing parts. good catch thanks. > dirlsit, returns the names of folders and files. i was using a > different method > http://thanksforallthefish.endofinternet.net/date-linuxversion.py > > try version 11 for yourself. in your home directory (ie: /home/name) > make a backup folder, put a few files/folders in it. then make a > backup2 folder, and make week1,week2week3week4 folders. version 11 > will copy the top level files under /home/name/backup , and recreate > the directory structure. so "You're not copying the files at the top > level at all; you don't process > the list called 'files', while you could probably safely copy *only* > the > files. " atleats for version 11 is not true. atleast not within the > bounds i have tested it. > > "Your name manipulations in this same function look risky, using > replace > when you presumably know that a string is either at the begin or end. > " > i know. i have several things that need to build up. like starting > from a relative position and going to a different position. username > would be part of the unc path if i could get that to work, and > week[1-4] is part of the name. > > the thing that gets me is version 11 works. well. but its is reading/ > writing to almost the same place (from backup, to backup2). defiantly > open to suggestions. > I didn't spot the dirlist before, since it's totally unnecessary. It just builds the same list you already have as 'files'. I thought you were looping over the names in dirs. copytree() is also redundant, as it'll cause the same files to be repeatedly copied. If you plan to use copytree, why bother using os.walk at all? I suggest you actually try writing a simple loop using os.walk to just display the names of all the files in and under a specified directory. Then maybe you'll understand what path, dirs, and files actually are. Once you have that, use string manipulation to change the source path name into a destination path, and print, rather than actually doing the shutilcopy2. DaveA From mdekauwe at gmail.com Sun Feb 13 19:12:00 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sun, 13 Feb 2011 16:12:00 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: <8d8ed5f9-b8aa-4d5b-9d69-1fa28d2bc216@y12g2000prf.googlegroups.com> On Feb 14, 10:16?am, Martin De Kauwe wrote: > On Feb 13, 6:35?pm, Terry Reedy wrote: > > > > > > > On 2/12/2011 9:20 PM, Martin De Kauwe wrote: > > > > On Feb 13, 5:12 am, Terry Reedy ?wrote: > > >> On 2/12/2011 1:24 AM, Martin De Kauwe wrote: > > > >>> The point of this posting was just to ask those that know, whether it > > >>> was a bad idea to use the class object in the way I had or was that > > >>> OK? And if I should have just used a dictionary, why? > > > >> Did you miss my suggestion to use a module rather than a class? > > >> Modules do not have some of the disadvantages of classes listed by J. Nagle. > > > >> -- > > >> Terry Jan Reedy > > > > Hi, sorry I did. I just re-read it, could you provide an example? > > > I am not sure what you are asking. tkinter.contants is one example. > > > > Sorry i am having a major mind blank this morning (I think this is > > > obvious!?). And it would meet all of the criteria outlined by John > > > Nagle? > > > A module will work fine if but only if you commit yourself to having all > > keys be legal Python identifiers. But that is usually not a problem with > > configuration values. > > > -- > > Terry Jan Reedy > > I think I got it, did you mean something like this? > > class Constants: > > ? ? radius_of_earth = 6.37122E+6 > ? ? days_as_yrs = 1.0 / 365.25 > ? ? m2_as_ha = 1E-4 ?# metres squared as hectares > ? ? g_as_tonnes = 1E-6 ?# grammes as tonnes > ? ? kg_as_tonnes = 1E-3 ?# kg as tonnes > ? ? kg_as_g = 1E+3 > > ? ? def __init__(self): > > ? ? ? ? self.radius_of_earth = self.__class__.radius_of_earth > ? ? ? ? self.days_as_yrs = self.__class__.days_as_yrs > ? ? ? ? self.m2_as_ha = self.__class__.m2_as_ha > ? ? ? ? self.g_as_tonnes = self.__class__.g_as_tonnes > ? ? ? ? self.kg_as_tonnes = self.__class__.kg_as_tonnes > ? ? ? ? self.kg_as_g = self.__class__.kg_as_g > > usage something like > > >>>from constants import Constants > >>>Constants.kg_as_g > >>>1000.0 > > Something similar for the params? > > thanks And then I guess define some default parameters and then use configobj to parse a .INI file. Then adjust those parameters change in the .INI file? e.g. from parameters import DefaultParameters as params # d -> comes from .INI file p = params() for key, value in d.iteritems(): # change anything read from file p.__dict__[key] = value ? From hayesjdno3 at yahoo.com Sun Feb 13 19:25:26 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 16:25:26 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> <87mxlzijwg.fsf@benfinney.id.au> Message-ID: On Feb 13, 6:39?pm, Ben Finney wrote: > ecu_jon writes: > > can you give an example of how to build a folder name, maybe as a > > string, with parts of it as variables, that have to be strung > > together. like x = "//servername/+variable+"/"+variable+"/" > > ? ? import os.path > > ? ? infile_path = os.path.join(["//servername", start_dir, other_dir]) > > Read the documentation for ?os.path.join?. It's fundamental if you're > working with filesystem paths. > > > when i did something liek that the end result string was like > > //servername/folder/folder\file and i got an error > > That path should work on MS Windows. If you want us to comment on the > error, you'll need to show the code here *and* the error traceback. > > -- > ?\ ? ? ? ??If this is your first visit to the USSR, you are welcome to | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?it.? ?hotel room, Moscow | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney here take a look. http://thanksforallthefish.endofinternet.net/testing.py the output looks like .... folder to copy = \\\\Mothera\\jon\week2 file to copy: C:\Users\jon\backup\configs\apache2.conf \\\\Mothera\\jon \week2\configs\apache2.conf folder to copy = \\\\Mothera\\jon\week2\configs ....#some lines ommited for brevity. From cs at zip.com.au Sun Feb 13 19:35:16 2011 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 14 Feb 2011 11:35:16 +1100 Subject: Call to Update All Tutorials to Python3.x Standards. In-Reply-To: References: Message-ID: <20110214003516.GA22905@cskk.homeip.net> On 13Feb2011 14:47, rantingrick wrote: | On Feb 13, 4:30?pm, Steven D'Aprano wrote: | > The official stance of the Python development team is that 2.7 and 3.x | > will co-exist for a long, long time. Removing 2.x tutorials would be | > cutting off our nose to spite our face. | | That is BS Steven and you know it! Of course we are going to support | 2.x for a long, long, time. Heck we even have downloads available for | Python1.x. I am talking about TUTORIALS steven, TUTORIALS! Steven is also talking about tutorials. Perhaps my comprehension skiils are weak; I am basing my assrtion on his use of the word "tutorials" in the sentence: Removing 2.x tutorials would be cutting off our nose to spite our face. I admit my reading here may be superficial and that you may be seeing a deeper intent. [...] | [...] Stop spreading lies Steven. [...] | PS: The only troll here is YOU! [...] I confess to finding these two sentences in your message contradictory. Again, my poor comprehension skills must be to blame. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ That's just the sort of bloody stupid name they would choose. - Reginald Mitchell, designer of the Spitfire From robert.kern at gmail.com Sun Feb 13 19:50:57 2011 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 13 Feb 2011 18:50:57 -0600 Subject: EPD 7.0 released In-Reply-To: <6a6a88a7-cbef-4b12-93e1-ba56a8cf7c0e@k9g2000yqi.googlegroups.com> References: <6a6a88a7-cbef-4b12-93e1-ba56a8cf7c0e@k9g2000yqi.googlegroups.com> Message-ID: On 2011-02-13 10:40 , sturlamolden wrote: > EPD is great, at least for scientific users. There is just one > installer, with everything we need, instead of struggling with dozens > of libraries to download, configure and build. It is still Python 2.7 > (not 3.1) due to libraries like SciPy. A subscription for EPD is also > a contribution to the development of NumPy and SciPy. I'd just like to jump in here to clear up this last statement as an Enthought employee. While Enthought and its employees do contribute to the development of numpy and scipy in various ways (and paying us money is a great way to let us do more of it!), there is no direct relationship to the revenue we get from EPD subscriptions and our contributions to numpy and scipy. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From tjreedy at udel.edu Sun Feb 13 20:02:05 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 13 Feb 2011 20:02:05 -0500 Subject: Class or Dictionary? In-Reply-To: <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: On 2/13/2011 6:16 PM, Martin De Kauwe wrote: > I think I got it, did you mean something like this? > > > class Constants: > > radius_of_earth = 6.37122E+6 > days_as_yrs = 1.0 / 365.25 > m2_as_ha = 1E-4 # metres squared as hectares > g_as_tonnes = 1E-6 # grammes as tonnes > kg_as_tonnes = 1E-3 # kg as tonnes > kg_as_g = 1E+3 > > def __init__(self): > > self.radius_of_earth = self.__class__.radius_of_earth > self.days_as_yrs = self.__class__.days_as_yrs > self.m2_as_ha = self.__class__.m2_as_ha > self.g_as_tonnes = self.__class__.g_as_tonnes > self.kg_as_tonnes = self.__class__.kg_as_tonnes > self.kg_as_g = self.__class__.kg_as_g > > > usage something like > >>> >from constants import Constants >>>> Constants.kg_as_g >>>> 1000.0 No, simpler. No class statememt necessarily needed. module constants ---------------- radius_of_earth = 6.37122E+6 days_as_yrs = 1.0 / 365.25 m2_as_ha = 1E-4 # metres squared as hectares g_as_tonnes = 1E-6 # grammes as tonnes kg_as_tonnes = 1E-3 # kg as tonnes kg_as_g = 1E+3 # could also have code to load stuff from other files usage ===== >>> import constants >>> constants.kg_as_g 1000.0 Real example >>> import math >>> math.pi, math.e (3.141592653589793, 2.718281828459045) -- Terry Jan Reedy From ben+python at benfinney.id.au Sun Feb 13 20:29:27 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Feb 2011 12:29:27 +1100 Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> <87mxlzijwg.fsf@benfinney.id.au> Message-ID: <87ipwnietk.fsf@benfinney.id.au> ecu_jon writes: > here take a look. > http://thanksforallthefish.endofinternet.net/testing.py I think you're confusing yourself by shoving lots of experimental lines into a large program and not isolating the problem. I see that you are trying lots of different ways of doing the same thing, and commenting some lines out arbitrarily. Instead, focus on the issue that's causing you confusion: constructing a filesystem path and testing whether it exists. Make a *minimal* program that shows the problem you're having. Post it *here* (that's why it's important that it be minimal), along with the exact error traceback you get from Python when you run it. Once you have something minimal that we, too, can run, we can comment better on its behaviour. -- \ ?Members of the general public commonly find copyright rules | `\ implausible, and simply disbelieve them.? ?Jessica Litman, | _o__) _Digital Copyright_ | Ben Finney From mdekauwe at gmail.com Sun Feb 13 20:33:40 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Sun, 13 Feb 2011 17:33:40 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: On Feb 14, 12:02?pm, Terry Reedy wrote: > On 2/13/2011 6:16 PM, Martin De Kauwe wrote: > > > > > > > I think I got it, did you mean something like this? > > > class Constants: > > > ? ? ?radius_of_earth = 6.37122E+6 > > ? ? ?days_as_yrs = 1.0 / 365.25 > > ? ? ?m2_as_ha = 1E-4 ?# metres squared as hectares > > ? ? ?g_as_tonnes = 1E-6 ?# grammes as tonnes > > ? ? ?kg_as_tonnes = 1E-3 ?# kg as tonnes > > ? ? ?kg_as_g = 1E+3 > > > ? ? ?def __init__(self): > > > ? ? ? ? ?self.radius_of_earth = self.__class__.radius_of_earth > > ? ? ? ? ?self.days_as_yrs = self.__class__.days_as_yrs > > ? ? ? ? ?self.m2_as_ha = self.__class__.m2_as_ha > > ? ? ? ? ?self.g_as_tonnes = self.__class__.g_as_tonnes > > ? ? ? ? ?self.kg_as_tonnes = self.__class__.kg_as_tonnes > > ? ? ? ? ?self.kg_as_g = self.__class__.kg_as_g > > > usage something like > > >>> >from constants import Constants > >>>> Constants.kg_as_g > >>>> 1000.0 > > No, simpler. No class statememt necessarily needed. > > module constants > ---------------- > > radius_of_earth = 6.37122E+6 > days_as_yrs = 1.0 / 365.25 > m2_as_ha = 1E-4 ?# metres squared as hectares > g_as_tonnes = 1E-6 ?# grammes as tonnes > kg_as_tonnes = 1E-3 ?# kg as tonnes > kg_as_g = 1E+3 > # could also have code to load stuff from other files > > usage > ===== > ?>>> import constants > ?>>> constants.kg_as_g > 1000.0 > > Real example > ?>>> import math > ?>>> math.pi, math.e > (3.141592653589793, 2.718281828459045) > > -- > Terry Jan Reedy Cool! Thanks this seems straight forward, however if I do it this way then once I change it (i.e. after reading user param file) I can't pass the changed version to another module can i? Or am I being stupid? Unless I do it my way I think import cons >>>print cons.kg_as_g >>>1000.0 >>>cons.kg_as_g = 23.4 >>>print cons.kg_as_g is fine. But if I call import cons in another module it would be back to 1000. right? Whereas if I do it as a class I can pass the adjusted instance? E.g. from constants import Constants c = Constants() I can then change "c" and pass this around? Apologies if I have got that totally wrong! From davea at ieee.org Sun Feb 13 20:48:22 2011 From: davea at ieee.org (Dave Angel) Date: Sun, 13 Feb 2011 20:48:22 -0500 Subject: files,folders,paths In-Reply-To: <169147.32700.qm@web33407.mail.mud.yahoo.com> References: <169147.32700.qm@web33407.mail.mud.yahoo.com> Message-ID: <4D5889E6.9030807@ieee.org> (You forgot to include the list in your response, and you neglected to properly quote the message you were replying to. That makes it quite hard to separate your remarks from mine) On 02/13/2011 07:19 PM, jon hayes wrote: > c:\users\name\backup\ #win7 >> c:\docs and settings\name\app data\backup\ #winxp >> /home/name/backup #linux and mac > > In what way do those imply a need for chdir() ? What's wrong with os.path.join() ? > the only commonality is the \backup > the chdir() is there to build the path name of the destination. > so c:\users\name\backup\folder1\folder2\file3 > in my code, doing the substution. Well, since chdir() is illegal inside the os.walk() context and unnecesary, I suggest you debug your original technique. Build the names with os.path.join(), as I've suggested twice before, and others have mentioned as well. > > these 3 lines > os.chdir(path) > cwd = os.getcwd() > leftover = cwd.replace(source, '') > in this case leftover = \folder1\folder2 > which gets added to the path for the destination in > shutil.copytree(os.getcwd(), destination+leftover) > > i looked at the relpath, it did not do exacly what i wanted. in version 11 of the code this works out well. I can't see how os.path.relpath() would be useful here. > > "And I quote from facbac-012a.py: > os.chdir("v:")" > i don't understand. is this a question? It is in context. If you read my message, I had just quoted you saying you did not change drive letters. > > "I suggest you actually try writing a simple loop using os.walk to just > display the names of all the files in and under a specified directory. > Then maybe you'll understand what path, dirs, and files actually are." > i started with that. look at the attached file, date-linuxversion.py. > the relative paths are not, quite, right. Well file you enclosed shows that you don't understand os.walk(). So learn it before trying to use it in a more complex setting. Why would you use the following sequence? filestring = str(files) filestring = filestring.strip("[") filestring = filestring.strip("]") filestring = filestring.strip("'") This is no way to process a list of filenames. > the thing with the copytree is, the line above is sopposed to check whether that folder exists. if it does not exist at all, then why not copy the whole thing? > same sort of thing with files. if not exist then do copy. that way nothing should get clobbered. > this is the observed behavior in version 11. > Why not copy the whole tree? Because once the code works, you'll be copying it many times. DaveA From hayesjdno3 at yahoo.com Sun Feb 13 22:52:25 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 19:52:25 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> <87mxlzijwg.fsf@benfinney.id.au> <87ipwnietk.fsf@benfinney.id.au> Message-ID: <84fa9665-a661-49c0-9ca1-17da9e78326d@y26g2000yqd.googlegroups.com> On Feb 13, 8:29?pm, Ben Finney wrote: > ecu_jon writes: > > here take a look. > >http://thanksforallthefish.endofinternet.net/testing.py > > I think you're confusing yourself by shoving lots of experimental lines > into a large program and not isolating the problem. I see that you are > trying lots of different ways of doing the same thing, and commenting > some lines out arbitrarily. > > Instead, focus on the issue that's causing you confusion: constructing a > filesystem path and testing whether it exists. > > Make a *minimal* program that shows the problem you're having. Post it > *here* (that's why it's important that it be minimal), along with the > exact error traceback you get from Python when you run it. > > Once you have something minimal that we, too, can run, we can comment > better on its behaviour. > > -- > ?\ ? ? ? ??Members of the general public commonly find copyright rules | > ? `\ ? ? ? ?implausible, and simply disbelieve them.? ?Jessica Litman, | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?_Digital Copyright_ | > Ben Finney this thing evolved i piece a a time. i got help from the wxpython people, and now that code has been stable for weeks. the function weekChoice came after talking to 2 CS grad studenst for 2 hours. deciding how to decide what week to pick. it seems to be solid. was picking week 1 up till 12:02 when i tested it on the 8th, then went to week 2. getusername probably should be unfunctionalized, and maybe dropped completely. homeDir is good on the 3 differnt platforms i have tested it on, linux, xp and 7. Ubuntu returned /home/name, 7 returned c:\Users\name \, xp returned c:\docs and settings\name\app data\ or something close to that. in version 011, source1 and destination1 worked fine. selectivly coping files or folders as needed. backupall has been volatile, but relatively stable last 2 weeks. in version 011, it does the if not folder and file detection. in version 12a, it does not. all of the functions cascade so im not really sure how i could cut something out, with out serious rewrite. i already did shrink it by gutting the wxpython parts. after uncommenting the 2 lines shutil.copytree(os.getcwd(), destination+leftover) shutil.copy2(filesource, filedest1) i get this as an traceback folder to copy = \\\\Mothera\\jon\week2 Traceback (most recent call last): File "I:\college\spring11\capstone-project\testing.py", line 86, in backupall() File "I:\college\spring11\capstone-project\testing.py", line 73, in backupall shutil.copytree(os.getcwd(), destination+leftover) File "C:\Python27\lib\shutil.py", line 174, in copytree os.makedirs(dst) File "C:\Python27\lib\os.py", line 150, in makedirs makedirs(head, mode) File "C:\Python27\lib\os.py", line 150, in makedirs makedirs(head, mode) File "C:\Python27\lib\os.py", line 150, in makedirs makedirs(head, mode) File "C:\Python27\lib\os.py", line 157, in makedirs mkdir(name, mode) WindowsError: [Error 161] The specified path is invalid: '\\\\\\\\' From hayesjdno3 at yahoo.com Sun Feb 13 23:02:46 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 20:02:46 -0800 (PST) Subject: files,folders,paths References: <169147.32700.qm@web33407.mail.mud.yahoo.com> Message-ID: On Feb 13, 8:48?pm, Dave Angel wrote: > (You forgot to include the list in your response, and you neglected to > properly quote the message you were replying to. ?That makes it quite > hard to separate your remarks from mine) > > On 02/13/2011 07:19 PM, jon hayes wrote: > > > c:\users\name\backup\ ?#win7 > >> c:\docs and settings\name\app data\backup\ ?#winxp > >> /home/name/backup ?#linux and mac > > > In what way do those imply a need for chdir() ? ?What's wrong with os.path.join() ? > > the only commonality is the \backup > > the chdir() is there to build the path name of the destination. > > so c:\users\name\backup\folder1\folder2\file3 > > in my code, doing the substution. > > Well, since chdir() is illegal inside the os.walk() context and > unnecesary, I suggest you debug your original technique. ?Build the > names with os.path.join(), as I've suggested twice before, and others > have mentioned as well. > > > > > these 3 lines > > os.chdir(path) > > cwd = os.getcwd() > > leftover = cwd.replace(source, '') > > in this case leftover = \folder1\folder2 > > which gets added to the path for the destination in > > shutil.copytree(os.getcwd(), destination+leftover) > > > i looked at the relpath, it did not do exacly what i wanted. in version 11 of the code this works out well. > > I can't see how os.path.relpath() would be useful here. > > > > > "And I quote from facbac-012a.py: > > ? ? ? ? ?os.chdir("v:")" > > i don't understand. is this a question? > > It is in context. ?If you read my message, I had just quoted you saying > you did not change drive letters. > > > > > "I suggest you actually try writing a simple loop using os.walk to just > > display the names of all the files in and under a specified directory. > > Then maybe you'll understand what ?path, dirs, and files actually are." > > i started with that. look at the attached file, date-linuxversion.py. > > the relative paths are not, quite, right. > > Well file you enclosed shows that you don't understand os.walk(). ?So > learn it before trying to use it in a more complex setting. ?Why would > you use the following sequence? > > ? ? ?filestring = str(files) > ? ? ?filestring = filestring.strip("[") > ? ? ?filestring = filestring.strip("]") > ? ? ?filestring = filestring.strip("'") > > This is no way to process a list of filenames. > > > the thing with the copytree is, the line above is sopposed to check whether that folder exists. if it does not exist at all, then why not copy the whole thing? > > same sort of thing with files. if not exist then do copy. that way nothing should get clobbered. > > this is the observed behavior in version 11. > > Why not copy the whole tree? ?Because once the code works, you'll be > copying it many times. > > DaveA if i do not change the directory how do i get the relative folder path. for example, starting with c:\users\name\backup\folder1\folder2\file as the oswalk drills down through the folders, when it is in the 'folder2' folder, if you do something like print dirs it would output just 'folder2' not the whole path or any of the other parts. so how do i know where to write this to on the destination relative to \\servername\username\week[1-4]\ or possibly that folder mounted as a drive in windows as v:\week[1-4]\ ? how do i build the output folder name. bear in mind it works great in version 011. i spent weeks, and tried maybe 7 different other ways before going down this path, so to speak. i thought about using a list. or an array. but you wouldnt know when oswalk starts bak from top level to go int another folder. let me think if i can say it another way. ... i think what you guys want me to do the osjoin on is this line destination = r"\\\\Mothera\\"+username+"\\"+weekstr or shutil.copytree(os.getcwd(), destination+leftover) please clarify. From hayesjdno3 at yahoo.com Sun Feb 13 23:19:04 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 20:19:04 -0800 (PST) Subject: files,folders,paths References: <169147.32700.qm@web33407.mail.mud.yahoo.com> Message-ID: this is a reply to both Dave Angel and Ben Finney. this version of testing i think incorperates what you guys are saying. testin1.py except maybe the os.join.path in the last function. here is the traceback Traceback (most recent call last): File "I:\college\spring11\capstone-project\testing.py", line 88, in backupall() File "I:\college\spring11\capstone-project\testing.py", line 84, in backupall shutil.copy2(filesource, filedest1) File "C:\Python27\lib\shutil.py", line 127, in copy2 copyfile(src, dst) File "C:\Python27\lib\shutil.py", line 82, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 2] No such file or directory: '//Mothera/week2\\jonI:\ \college\\spring11\\capstone-project\\changelog.txt' it looks like it needs os.walk and the other for line to dig through the folders. this being the whole path I:\\college\\spring11\\capstone-project\\changelog.txt of source. From hayesjdno3 at yahoo.com Sun Feb 13 23:20:25 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 20:20:25 -0800 (PST) Subject: files,folders,paths References: <169147.32700.qm@web33407.mail.mud.yahoo.com> Message-ID: <0eece850-542d-4fdb-aa03-170a7deb04e1@j11g2000yqh.googlegroups.com> http://thanksforallthefish.endofinternet.net/testing1.py From lists at cheimes.de Sun Feb 13 23:39:02 2011 From: lists at cheimes.de (Christian Heimes) Date: Mon, 14 Feb 2011 05:39:02 +0100 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 14.02.2011 00:12, schrieb rantingrick: > False! There IS harm in using super when super not needed. The > difference is readability! And don't downplay that aspect. You > yourself have said this in the past. It seems *some* of us have very > short memories. Of course you are entitled to have your own opinion and own coding style. You are also allowed to disregard the opinion of experienced Python developers, who really know what they are talking about. But please DO NOT teach new Python users wrong coding! I assume Benjamin will follow the right lead here. If you have a short memory then you should definitely use one way -- the correct way for all cases -- to call the parent's class init method. Otherwise your future self is going to hate your current self for introducing potential buggy code. Have fun ;) Christian From jasons at tng.com.au Mon Feb 14 00:05:36 2011 From: jasons at tng.com.au (Jason Sergeant) Date: Mon, 14 Feb 2011 16:05:36 +1100 Subject: Sending email via proxy Message-ID: <7253D8BECD8D2646A59EE613AFA243C50239505D2C@SBS.Netlor.local> Hello, Is chilkat the best option for doing this?(Sending email via proxy) Kind Regards, Jason Sergeant This email has been processed by SmoothZap - www.smoothwall.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Feb 14 00:12:02 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Feb 2011 16:12:02 +1100 Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> <87mxlzijwg.fsf@benfinney.id.au> <87ipwnietk.fsf@benfinney.id.au> <84fa9665-a661-49c0-9ca1-17da9e78326d@y26g2000yqd.googlegroups.com> Message-ID: <87aahzi4il.fsf@benfinney.id.au> ecu_jon writes: > On Feb 13, 8:29?pm, Ben Finney wrote: > > Instead, focus on the issue that's causing you confusion: > > constructing a filesystem path and testing whether it exists. > > > > Make a *minimal* program that shows the problem you're having. Post it > > *here* (that's why it's important that it be minimal), along with the > > exact error traceback you get from Python when you run it. > > > > Once you have something minimal that we, too, can run, we can comment > > better on its behaviour. > > this thing evolved i piece a a time. I don't doubt it. But clearing up confusion over what a big wad of code does is best done by trying to isolate the problem into a small piece of code. > i got help from the wxpython people, and now that code has been stable > for weeks. > > the function weekChoice came after talking to 2 CS grad studenst for 2 > hours. deciding how to decide what week to pick. it seems to be solid. > was picking week 1 up till 12:02 when i tested it on the 8th, then > went to week 2. This all sounds as though you're doing ball-of-mud programming: keep throwing more code at the program, and whatever sticks must stay there forever without understanding what it's doing. That's a bad idea. I hope you can already see why. Really, please make a new, minimal, complete example that still exhibits the specific confusing behaviour, and *post it in a message* (not at a URL), so we can see the problem in isolation. If it's more than a dozen lines, it's doing too much for the problem you're talking about here. -- \ ?We cannot solve our problems with the same thinking we used | `\ when we created them.? ?Albert Einstein | _o__) | Ben Finney From wangcoeus at gmail.com Mon Feb 14 00:47:55 2011 From: wangcoeus at gmail.com (Wang Coeus) Date: Mon, 14 Feb 2011 07:47:55 +0200 Subject: How to create a dict based on such a file? Message-ID: Hi all, I am new to python. Currently I encountered a problem, please help me to solve this. Thanks in advance! I have a file like below: ++++++++++++++++++++++++++++++++++++++ block1 { key1=value1 key2=value2 key3=value3 } block2 { key1=value4 key2=value5 key4=value6 } ... blockn { key1=value7 key2=value8 keyn=valuen } +++++++++++++++++++++++++++++++++++++++ Different block may have different keys and even same key in different blocks may have different values. Now I want to get a function, which like this: func(key) and it will return a dictionary as below: func(key1) = [block1:value1,block2:value4,...,blockn:value7] and if one block has no "key1" parameter, it will not include in this dict. Thanks a lot! -- Coeus In the middle of every difficulty lies opportunity. -- Albert Einstein From hayesjdno3 at yahoo.com Mon Feb 14 01:20:06 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Sun, 13 Feb 2011 22:20:06 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> <87mxlzijwg.fsf@benfinney.id.au> <87ipwnietk.fsf@benfinney.id.au> <84fa9665-a661-49c0-9ca1-17da9e78326d@y26g2000yqd.googlegroups.com> <87aahzi4il.fsf@benfinney.id.au> Message-ID: <1df021e1-24ea-4a05-9b08-0e65dd72cbea@x11g2000yqc.googlegroups.com> On Feb 14, 12:12?am, Ben Finney wrote: > ecu_jon writes: > > On Feb 13, 8:29?pm, Ben Finney wrote: > > > Instead, focus on the issue that's causing you confusion: > > > constructing a filesystem path and testing whether it exists. > > > > Make a *minimal* program that shows the problem you're having. Post it > > > *here* (that's why it's important that it be minimal), along with the > > > exact error traceback you get from Python when you run it. > > > > Once you have something minimal that we, too, can run, we can comment > > > better on its behaviour. > > > this thing evolved i piece a a time. > > I don't doubt it. But clearing up confusion over what a big wad of code > does is best done by trying to isolate the problem into a small piece of > code. > > > i got help from the wxpython people, and now that code has been stable > > for weeks. > > > the function weekChoice came after talking to 2 CS grad studenst for 2 > > hours. deciding how to decide what week to pick. it seems to be solid. > > was picking week 1 up till 12:02 when i tested it on the 8th, then > > went to week 2. > > This all sounds as though you're doing ball-of-mud programming: keep > throwing more code at the program, and whatever sticks must stay there > forever without understanding what it's doing. > > That's a bad idea. I hope you can already see why. > > Really, please make a new, minimal, complete example that still exhibits > the specific confusing behaviour, and *post it in a message* (not at a > URL), so we can see the problem in isolation. If it's more than a dozen > lines, it's doing too much for the problem you're talking about here. > > -- > ?\ ? ? ? ??We cannot solve our problems with the same thinking we used | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? when we created them.? ?Albert Einstein | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney well it seems not to be the difference between versions 11,12,12a. it works great on my linux box. i get all these errors on the windows boxes. i think it has to do with the folder name, and strings etc. got to se if i can use os.join.path for the whole naming. From georg at python.org Mon Feb 14 01:40:00 2011 From: georg at python.org (Georg Brandl) Date: Mon, 14 Feb 2011 07:40:00 +0100 Subject: [RELEASED] Python 3.2 rc 3 Message-ID: <4D58CE40.1010408@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm happy to announce the third release candidate of Python 3.2. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * a much improved ssl module with support for SSL contexts and certificate hostname matching * a sysconfig module to access configuration information * additions to the shutil module, among them archive file support * many enhancements to configparser, among them mapping protocol support * improvements to pdb, the Python debugger * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk1YzkAACgkQN9GcIYhpnLAggwCfQ92djMinrmNkGI4Ma3VRqrcX EWIAn16kTEJtvEH/7DJApp7YdhnmIRBd =NJ1B -----END PGP SIGNATURE----- From aspineux at gmail.com Mon Feb 14 02:10:18 2011 From: aspineux at gmail.com (aspineux) Date: Sun, 13 Feb 2011 23:10:18 -0800 (PST) Subject: How to create a dict based on such a file? References: Message-ID: <93fc1b9d-e0f9-442f-811c-c35d7a0ce15f@k9g2000yqi.googlegroups.com> On 14 f?v, 06:47, Wang Coeus wrote: > Hi all, > I am new to python. Currently I encountered a problem, please help me to > solve this. Thanks in advance! > I have a file like below: ConfigParser Library does exacly what you want but with .ini file format [block1] key1=value1 key2=value2 ... Can you change the format of your file ? If so import ConfigParser config=ConfigParser.RawConfigParser(config_default) try: config.readfp(open(filename, 'r')) except Exception, e: logging.error('error reading configuration file %s: %s', filename, e) sys.exit(1) def func(config, key1): result={} for section in config.sections(): if config.has_option(section, key1): result[section]=config.get(section, key1) return result If not, you need to parse youre file, and the some question : How or what generate this file, is it always the same format ? Could it chnage, for exemple for block1 { key1=value1 key2=value2 } or at least block1 { key1=value1 key2=value2 } Is-it big, too big to keep in memory ? > ++++++++++++++++++++++++++++++++++++++ > block1 > { > ? key1=value1 > ? key2=value2 > ? key3=value3} > > block2 > { > ? key1=value4 > ? key2=value5 > ? key4=value6} > > ... > blockn > { > ? key1=value7 > ? key2=value8 > ? keyn=valuen} > > +++++++++++++++++++++++++++++++++++++++ > Different block may have different keys and even same key in different > blocks may have different values. > > Now I want to get a function, which like this: > func(key) > and it will return a dictionary as below: > func(key1) = [block1:value1,block2:value4,...,blockn:value7] > and if one block has no "key1" parameter, it will not include in this > dict. > > Thanks a lot! > -- > Coeus > In the middle of every difficulty lies opportunity. > ? ? ? ? ? ? ? ? -- Albert Einstein From yanghatespam at gmail.com Mon Feb 14 02:52:24 2011 From: yanghatespam at gmail.com (Yang Zhang) Date: Mon, 14 Feb 2011 15:52:24 +0800 Subject: Python subprocesses experience mysterious delay in receiving stdin EOF In-Reply-To: References: <4D52037E.4000809@mrabarnett.plus.com> <4D52C0C7.4040004@sequans.com> Message-ID: Anybody else see this issue? On Thu, Feb 10, 2011 at 10:37 AM, Yang Zhang wrote: > On Thu, Feb 10, 2011 at 12:28 AM, Jean-Michel Pichavant > wrote: >> Yang Zhang wrote: >>> >>> On Wed, Feb 9, 2011 at 11:01 AM, MRAB wrote: >>> >>>> >>>> On 09/02/2011 01:59, Yang Zhang wrote: >>>> >>>>> >>>>> I reduced a problem I was seeing in my application down into the >>>>> following test case. In this code, a parent process concurrently >>>>> spawns 2 (you can spawn more) subprocesses that read a big message >>>>> from the parent over stdin, sleep for 5 seconds, and write something >>>>> back. However, there's unexpected waiting happening somewhere, causing >>>>> the code to complete in 10 seconds instead of the expected 5. >>>>> >>>>> If you set `verbose=True`, you can see that the straggling subprocess >>>>> is receiving most of the messages, then waiting for the last chunk of >>>>> 3 chars---it's not detecting that the pipe has been closed. >>>>> Furthermore, if I simply don't do anything with the second process >>>>> (`doreturn=True`), the first process will *never* see the EOF. >>>>> >>>>> Any ideas what's happening? Further down is some example output. >>>>> Thanks in advance. >>>>> >>>>> ? ?from subprocess import * >>>>> ? ?from threading import * >>>>> ? ?from time import * >>>>> ? ?from traceback import * >>>>> ? ?import sys >>>>> ? ?verbose = False >>>>> ? ?doreturn = False >>>>> ? ?msg = (20*4096+3)*'a' >>>>> ? ?def elapsed(): return '%7.3f' % (time() - start) >>>>> ? ?if sys.argv[1:]: >>>>> ? ? ?start = float(sys.argv[2]) >>>>> ? ? ?if verbose: >>>>> ? ? ? ?for chunk in iter(lambda: sys.stdin.read(4096), ''): >>>>> ? ? ? ? ?print>> ?sys.stderr, '..', time(), sys.argv[1], 'read', >>>>> len(chunk) >>>>> ? ? ?else: >>>>> ? ? ? ?sys.stdin.read() >>>>> ? ? ?print>> ?sys.stderr, elapsed(), '..', sys.argv[1], 'done reading' >>>>> ? ? ?sleep(5) >>>>> ? ? ?print msg >>>>> ? ?else: >>>>> ? ? ?start = time() >>>>> ? ? ?def go(i): >>>>> ? ? ? ?print elapsed(), i, 'starting' >>>>> ? ? ? ?p = Popen(['python','stuckproc.py',str(i), str(start)], >>>>> stdin=PIPE, stdout=PIPE) >>>>> ? ? ? ?if doreturn and i == 1: return >>>>> ? ? ? ?print elapsed(), i, 'writing' >>>>> ? ? ? ?p.stdin.write(msg) >>>>> ? ? ? ?print elapsed(), i, 'closing' >>>>> ? ? ? ?p.stdin.close() >>>>> ? ? ? ?print elapsed(), i, 'reading' >>>>> ? ? ? ?p.stdout.read() >>>>> ? ? ? ?print elapsed(), i, 'done' >>>>> ? ? ?ts = [Thread(target=go, args=(i,)) for i in xrange(2)] >>>>> ? ? ?for t in ts: t.start() >>>>> ? ? ?for t in ts: t.join() >>>>> >>>>> Example output: >>>>> >>>>> ? ? ?0.001 0 starting >>>>> ? ? ?0.003 1 starting >>>>> ? ? ?0.005 0 writing >>>>> ? ? ?0.016 1 writing >>>>> ? ? ?0.093 0 closing >>>>> ? ? ?0.093 0 reading >>>>> ? ? ?0.094 1 closing >>>>> ? ? ?0.094 1 reading >>>>> ? ? ?0.098 .. 1 done reading >>>>> ? ? ?5.103 1 done >>>>> ? ? ?5.108 .. 0 done reading >>>>> ? ? 10.113 0 done >>>>> >>>>> >>>> >>>> I changed 'python' to the path of python.exe and 'stuckproc.py' to its >>>> full path and tried it with Python 2.7 on Windows XP Pro. It worked as >>>> expected. >>>> >>> >>> Good point - I didn't specify that I'm seeing this on Linux (Ubuntu >>> 10.04's Python 2.6). >>> >>> >> >> python test.py ? 0.000 0 starting >> ?0.026 0 writing >> ?0.026 0 closing >> ?0.026 0 reading >> ?0.029 .. 0 done reading >> ?0.030 1 starting >> ?0.038 1 writing >> ?0.058 1 closing >> ?0.058 1 reading >> ?0.061 .. 1 done reading >> ?5.026 0 done >> ?5.061 1 done >> >> on debian lenny (Python 2.5) >> >> JM >> > > FWIW, this is consistently reproduce-able across all the Ubuntu 10.04s > I've tried. You may need to increase the message size so that it's > large enough for your system. > > -- > Yang Zhang > http://yz.mit.edu/ > -- Yang Zhang http://yz.mit.edu/ From tjreedy at udel.edu Mon Feb 14 03:12:07 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 14 Feb 2011 03:12:07 -0500 Subject: Class or Dictionary? In-Reply-To: References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: On 2/13/2011 8:33 PM, Martin De Kauwe wrote: > Cool! Thanks this seems straight forward, however if I do it this way > then once I change it (i.e. after reading user param file) I can't > pass the changed version to another module can i? Or am I being > stupid? Unless I do it my way I think > > import cons >>>> print cons.kg_as_g >>>> 1000.0 >>>> cons.kg_as_g = 23.4 >>>> print cons.kg_as_g > > is fine. > > But if I call import cons in another module it would be back to 1000. > right? Wrong. There is one and only one module object, imported into (which means bound to a name in) as many modules as you want. If you change an attribute, it is changed for all. If you add attributes from any module, they are added for all, regardless of whether or not they have already imported it. No different from changing a list or dict with multiple names. The math module is read only. User python-coded modules are read-write. -- Terry Jan Reedy From davea at ieee.org Mon Feb 14 03:30:17 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 14 Feb 2011 03:30:17 -0500 Subject: Class or Dictionary? In-Reply-To: References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: <4D58E819.9020304@ieee.org> On 01/-10/-28163 02:59 PM, Martin De Kauwe wrote: > On Feb 14, 12:02 pm, Terry Reedy wrote: >> >> > > Cool! Thanks this seems straight forward, however if I do it this way > then once I change it (i.e. after reading user param file) I can't > pass the changed version to another module can i? Or am I being > stupid? Unless I do it my way I think > > import cons >>>> print cons.kg_as_g >>>> 1000.0 >>>> cons.kg_as_g =3.4 >>>> print cons.kg_as_g > > is fine. > > But if I call import cons in another module it would be back to 1000. > right? Whereas if I do it as a class I can pass the adjusted instance? > E.g. > > from constants import Constants > c =onstants() > > I can then change "c" and pass this around? > > Apologies if I have got that totally wrong! > Yep, you've got it totally wrong. As long as your import is the kind you show here, changes are persistent. Other modules that import cons will get the one you modified, not re-execute the source. If you had tried something like from cons import kg then you'd have a separate local binding. So don't do that. DaveA From mdekauwe at gmail.com Mon Feb 14 03:44:22 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Mon, 14 Feb 2011 00:44:22 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: On Feb 14, 7:12?pm, Terry Reedy wrote: > On 2/13/2011 8:33 PM, Martin De Kauwe wrote: > > > Cool! Thanks this seems straight forward, however if I do it this way > > then once I change it (i.e. after reading user param file) I can't > > pass the changed version to another module can i? Or am I being > > stupid? Unless I do it my way I think > > > import cons > >>>> print cons.kg_as_g > >>>> 1000.0 > >>>> cons.kg_as_g = 23.4 > >>>> print cons.kg_as_g > > > is fine. > > > But if I call import cons in another module it would be back to 1000. > > right? > > Wrong. There is one and only one module object, imported into (which > means bound to a name in) as many modules as you want. If you change an > attribute, it is changed for all. If you add attributes from any module, > they are added for all, regardless of whether or not they have already > imported it. No different from changing a list or dict with multiple names. > > The math module is read only. User python-coded modules are read-write. > > -- > Terry Jan Reedy OK thanks I'll go over what I have done as I must have done something stupid as I thought I tested it earlier and couldn't get it to work like you suggested. Broadly this is how I am using it (incase it is obvious, although perhaps it just works and I need to recheck). Apart from that thanks for the modules idea it is very simple and seems to be working nicely in principle. from other_model import OtherSubModel class Model: def __init__(self): # included other external modules (i.e. in other files) om = OtherSubModel() def run(self): # call other submodel and pass params om.run(params) and the other file would look something like this class OtherSubModel: def __init__(self): #some stuff def run(params): From hayesjdno3 at yahoo.com Mon Feb 14 04:06:59 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Mon, 14 Feb 2011 01:06:59 -0800 (PST) Subject: files,folders,paths References: <9bca89a6-b85d-41ce-948b-bc8342c59774@d28g2000yqc.googlegroups.com> <4d57c622$0$29997$c3e8da3$5496439d@news.astraweb.com> <87mxlzijwg.fsf@benfinney.id.au> <87ipwnietk.fsf@benfinney.id.au> <84fa9665-a661-49c0-9ca1-17da9e78326d@y26g2000yqd.googlegroups.com> <87aahzi4il.fsf@benfinney.id.au> <1df021e1-24ea-4a05-9b08-0e65dd72cbea@x11g2000yqc.googlegroups.com> Message-ID: i think i got it. my dirlist wasn't the right way to go, i needed to iterate thu what oswalk was giving me in dirs, and files. not bruteforce strip to a string. i have been starting at an early version and a later version for the last 4 hours or so, and i think i have it this only handles the folders. i wanted to try out the logic before i doubled up and parsed files too. substitute this in for the backup function. and for now the source and destination functions are in this to. ill clean it up once i test it more. backupdir = os.path.join(homedir, "backup") remotedir = os.path.join(homedir, "backup2") weekstr = "week"+str(week) remotedirweek = os.path.join(remotedir, weekstr) print '################################################################' for (path, dirs, files) in os.walk(backupdir): print "current path is : ",path print "current dir is : ",dirs print "current files are: ",files for fname in dirs: os.chdir(path) leftover = os.getcwd().replace(backupdir, '') print "leftover is:",leftover print "remotedirweek is:",remotedirweek currentdir1 = remotedirweek+leftover if not os.path.isdir(currentdir1): print "currentdir1:",currentdir1 print "i should copy teh folderz",os.path.join(currentdir1,fname) shutil.copytree(os.getcwd(),os.path.join(currentdir1,fname)) From davea at ieee.org Mon Feb 14 04:43:02 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 14 Feb 2011 04:43:02 -0500 Subject: files,folders,paths In-Reply-To: References: <169147.32700.qm@web33407.mail.mud.yahoo.com> Message-ID: <4D58F926.4000209@ieee.org> On 01/-10/-28163 02:59 PM, ecu_jon wrote: > this is a reply to both Dave Angel and Ben Finney. this version of > testing i think incorperates what you guys are saying. > testin1.py > except maybe the os.join.path in the last function. > here is the traceback > Traceback (most recent call last): > File "I:\college\spring11\capstone-project\testing.py", line 88, in > > backupall() > File "I:\college\spring11\capstone-project\testing.py", line 84, in > backupall > shutil.copy2(filesource, filedest1) > File "C:\Python27\lib\shutil.py", line 127, in copy2 > copyfile(src, dst) > File "C:\Python27\lib\shutil.py", line 82, in copyfile > with open(dst, 'wb') as fdst: > IOError: [Errno 2] No such file or directory: '//Mothera/week2\\jonI:\ > \college\\spring11\\capstone-project\\changelog.txt' > > it looks like it needs os.walk and the other for line to dig through > the folders. > this being the whole path > I:\\college\\spring11\\capstone-project\\changelog.txt of source. > Simplify the code. def weekChoice() return 1 + (datetime.now().day -1) // 7 #weeks go from 1 to 5 def backupall(): source = source1() destination = destination2() print "copy tree ", source, destination if os.path.exists(destination): if os.path.isdir(destination): shutil.rmtree(destination) else: os.unlink(destination) shutil.copytree(source, destination) return All that nonsense with curdir was messing up your thinking. I'm not going to try to debug your destination2() function, but I would point out that when you use os.path.join(), please let it do the work for you. It takes any number of arguments, and those arguments should not have extra slashes or backslashes in them. The leading slashes are okay for the first node, if you want a unc. It would have been much easier if you had made source and destination arguments to the backupall() function. It then might have become clear that it's simply copytree(), with the extra requirement of deleting whatever used to be there. Now if you aren't allowed to delete what was already there, then you can't use copytree, and need to start over with os.walk(). DaveA From davea at ieee.org Mon Feb 14 04:51:20 2011 From: davea at ieee.org (Dave Angel) Date: Mon, 14 Feb 2011 04:51:20 -0500 Subject: Class or Dictionary? In-Reply-To: References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: <4D58FB18.7060307@ieee.org> On 01/-10/-28163 02:59 PM, Martin De Kauwe wrote: > > > from other_model import OtherSubModel > class Model: > > def __init__(self): > > # included other external modules (i.e. in other files) > om =therSubModel() > > def run(self): > # call other submodel and pass params > om.run(params) > What's om supposed to be? You define a local variable in one method, and try to use it in a different one ???? Perhaps you meant self.om = > class OtherSubModel: > def __init__(self): > #some stuff > > def run(params): You're missing a self here in the formal parameter list. DaveA From hayesjdno3 at yahoo.com Mon Feb 14 04:53:34 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Mon, 14 Feb 2011 01:53:34 -0800 (PST) Subject: files,folders,paths References: <169147.32700.qm@web33407.mail.mud.yahoo.com> Message-ID: On Feb 14, 4:43?am, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, ecu_jon wrote: > > > > > this is a reply to both Dave Angel and Ben Finney. this version of > > testing i think incorperates what you guys are saying. > > testin1.py > > except maybe the os.join.path in the last function. > > here is the traceback > > Traceback (most recent call last): > > ? ?File "I:\college\spring11\capstone-project\testing.py", line 88, in > > > > ? ? ?backupall() > > ? ?File "I:\college\spring11\capstone-project\testing.py", line 84, in > > backupall > > ? ? ?shutil.copy2(filesource, filedest1) > > ? ?File "C:\Python27\lib\shutil.py", line 127, in copy2 > > ? ? ?copyfile(src, dst) > > ? ?File "C:\Python27\lib\shutil.py", line 82, in copyfile > > ? ? ?with open(dst, 'wb') as fdst: > > IOError: [Errno 2] No such file or directory: '//Mothera/week2\\jonI:\ > > \college\\spring11\\capstone-project\\changelog.txt' > > > it looks like it needs os.walk and the other for line to dig through > > the folders. > > this being the whole path > > I:\\college\\spring11\\capstone-project\\changelog.txt of source. > > Simplify the code. > > def weekChoice() > ? ? ?return 1 + (datetime.now().day -1) // 7 ? #weeks go from 1 to 5 > > def backupall(): > ? ? ?source = source1() > ? ? ?destination = destination2() > ? ? ?print "copy tree ", source, destination > ? ? ?if os.path.exists(destination): > ? ? ? ? ?if os.path.isdir(destination): > ? ? ? ? ? ? ?shutil.rmtree(destination) > ? ? ? ? else: > ? ? ? ? ? ? ?os.unlink(destination) > ? ? ?shutil.copytree(source, destination) > ? ? ?return > > All that nonsense with curdir was messing up your thinking. > > I'm not going to try to debug your destination2() function, but I would > point out that when you use os.path.join(), please let it do the work > for you. ?It takes any number of arguments, and those arguments should > not have extra slashes or backslashes in them. ?The leading slashes are > okay for the first node, if you want a unc. > > It would have been much easier if you had made source and destination > arguments to the backupall() function. ?It then might have become clear > that it's simply copytree(), with the extra requirement of deleting > whatever used to be there. > > Now if you aren't allowed to delete what was already there, then you > can't use copytree, and need to start over with os.walk(). > > DaveA and dest2 was me trying different ways to write to the sever, unc or mounted drive. that's for later :P i missed this "as missing parent directories." shutil.copytree(src, dst[, symlinks=False[, ignore=None]])? Recursively copy an entire directory tree rooted at src. The destination directory, named by dst, must not already exist; it will be created as well as missing parent directories. so for testing i did the copy once. deleted the files in top folder, and deleted a folder deeper in. gave error when tried to copytree the deeper in folder. is there something like mkdir? From mdekauwe at gmail.com Mon Feb 14 04:57:15 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Mon, 14 Feb 2011 01:57:15 -0800 (PST) Subject: Class or Dictionary? References: <4d55d0bd$0$29980$c3e8da3$5496439d@news.astraweb.com> <02eee9f2-2255-4702-b545-8e5372e92d9c@y30g2000prf.googlegroups.com> <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> Message-ID: <090af3b8-ade9-4994-8102-cb096f67bec6@x4g2000prf.googlegroups.com> On Feb 14, 8:51?pm, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, Martin De Kauwe wrote: > > > > > > from other_model import OtherSubModel > > class Model: > > > ? ? ?def __init__(self): > > > ? ? ? ? ?# included other external modules (i.e. in other files) > > ? ? ? ? ?om =therSubModel() > > > ? ? ?def run(self): > > ? ? ? ? ?# call other submodel and pass params > > ? ? ? ? ?om.run(params) > > What's om supposed to be? ?You define a local variable in one method, > and try to use it in a different one ???? > > Perhaps you meant ?self.om = > > ?> class OtherSubModel: > ?> ? ? def __init__(self): > ?> ? ? ? ? #some stuff > ?> > ?> ? ? def run(params): > > You're missing a self here in the formal parameter list. > > DaveA I was trying to write a smaller version of broadly what I think i am doing, perhaps I am not implementing it correctly. I have one model which I have coded as a class, there were a few parts which could be used separately (sub-models). So I decided to make them separate classes in separate files which I *thought* I could just join up into one package at run time. This way I could also use these modules separately. So in the dummy example the other file is imported from other_model import OtherSubModel amd om = OtherSubModel was me making an instance of it? And then when I called the *run* part of this sub-model I was passing it the parameter file. I am sensing I have this wrong? From hayesjdno3 at yahoo.com Mon Feb 14 05:10:33 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Mon, 14 Feb 2011 02:10:33 -0800 (PST) Subject: files,folders,paths References: <169147.32700.qm@web33407.mail.mud.yahoo.com> Message-ID: <2c3c533d-5c7a-4c4e-8f52-25ae80fcf761@o8g2000vbq.googlegroups.com> On Feb 14, 4:43?am, Dave Angel wrote: > On 01/-10/-28163 02:59 PM, ecu_jon wrote: > > > > > this is a reply to both Dave Angel and Ben Finney. this version of > > testing i think incorperates what you guys are saying. > > testin1.py > > except maybe the os.join.path in the last function. > > here is the traceback > > Traceback (most recent call last): > > ? ?File "I:\college\spring11\capstone-project\testing.py", line 88, in > > > > ? ? ?backupall() > > ? ?File "I:\college\spring11\capstone-project\testing.py", line 84, in > > backupall > > ? ? ?shutil.copy2(filesource, filedest1) > > ? ?File "C:\Python27\lib\shutil.py", line 127, in copy2 > > ? ? ?copyfile(src, dst) > > ? ?File "C:\Python27\lib\shutil.py", line 82, in copyfile > > ? ? ?with open(dst, 'wb') as fdst: > > IOError: [Errno 2] No such file or directory: '//Mothera/week2\\jonI:\ > > \college\\spring11\\capstone-project\\changelog.txt' > > > it looks like it needs os.walk and the other for line to dig through > > the folders. > > this being the whole path > > I:\\college\\spring11\\capstone-project\\changelog.txt of source. > > Simplify the code. > > def weekChoice() > ? ? ?return 1 + (datetime.now().day -1) // 7 ? #weeks go from 1 to 5 > > def backupall(): > ? ? ?source = source1() > ? ? ?destination = destination2() > ? ? ?print "copy tree ", source, destination > ? ? ?if os.path.exists(destination): > ? ? ? ? ?if os.path.isdir(destination): > ? ? ? ? ? ? ?shutil.rmtree(destination) > ? ? ? ? else: > ? ? ? ? ? ? ?os.unlink(destination) > ? ? ?shutil.copytree(source, destination) > ? ? ?return > > All that nonsense with curdir was messing up your thinking. > > I'm not going to try to debug your destination2() function, but I would > point out that when you use os.path.join(), please let it do the work > for you. ?It takes any number of arguments, and those arguments should > not have extra slashes or backslashes in them. ?The leading slashes are > okay for the first node, if you want a unc. > > It would have been much easier if you had made source and destination > arguments to the backupall() function. ?It then might have become clear > that it's simply copytree(), with the extra requirement of deleting > whatever used to be there. > > Now if you aren't allowed to delete what was already there, then you > can't use copytree, and need to start over with os.walk(). > > DaveA i thought i had it. i think im going to sleep on it. here is what im working with right now. jsut trying to make folders stuff work. def backupall(): week = weekChoice() weekstr = "week"+str(week) source = source1() #was backupdir destination = destination1() #was remotedir #destinationweek = os.path.join(destination, weekstr) for (path, dirs, files) in os.walk(source): for fname in dirs: os.chdir(path) leftover = os.getcwd().replace(source, '') #print "leftover is:",leftover currentdir = destination+leftover if not os.path.isdir(currentdir): print "leftover is:",leftover print "currentdir1:",currentdir print "i should copy teh folderz",os.path.join(currentdir,fname) os.mkdir(os.path.join(currentdir,fname),0755) it is not making the top level folder, then tries to create deeper folders and fails. part of the traceback. os.mkdir(os.path.join(currentdir,fname),0755) WindowsError: [Error 3] The system cannot find the path specified: 'C:\ \Users\\jon\\backup2\\week2\\configs\\squid_files' From mdekauwe at gmail.com Mon Feb 14 05:10:41 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Mon, 14 Feb 2011 02:10:41 -0800 (PST) Subject: How to create a dict based on such a file? References: <93fc1b9d-e0f9-442f-811c-c35d7a0ce15f@k9g2000yqi.googlegroups.com> Message-ID: <43f6deb3-a327-4fd5-bcac-c0040837de36@o39g2000prb.googlegroups.com> On Feb 14, 6:10?pm, aspineux wrote: > On 14 f?v, 06:47, Wang Coeus wrote: > > > Hi all, > > I am new to python. Currently I encountered a problem, please help me to > > solve this. Thanks in advance! > > I have a file like below: > > ConfigParser Library does exacly what you want but with .ini file > format > [block1] > key1=value1 > key2=value2 > ... > > Can you change the format of your file ? If so > > import ConfigParser > config=ConfigParser.RawConfigParser(config_default) > try: > ? ? config.readfp(open(filename, 'r')) > except Exception, e: > ? ? logging.error('error reading configuration file %s: %s', filename, > e) > ? ? sys.exit(1) > > def func(config, key1): > ? ? result={} > ? ? for section in config.sections(): > ? ? ? ? if config.has_option(section, key1): > ? ? ? ? ? ? result[section]=config.get(section, key1) > ? ? return result > > If not, you need to parse youre file, and the some question : > How or what generate this file, is it always the same format ? Could > it chnage, for exemple for > > block1 { key1=value1 key2=value2 } > > or at least > > block1 { > > key1=value1 > key2=value2 > > } > > Is-it big, too big to keep in memory ? > > > > > ++++++++++++++++++++++++++++++++++++++ > > block1 > > { > > ? key1=value1 > > ? key2=value2 > > ? key3=value3} > > > block2 > > { > > ? key1=value4 > > ? key2=value5 > > ? key4=value6} > > > ... > > blockn > > { > > ? key1=value7 > > ? key2=value8 > > ? keyn=valuen} > > > +++++++++++++++++++++++++++++++++++++++ > > Different block may have different keys and even same key in different > > blocks may have different values. > > > Now I want to get a function, which like this: > > func(key) > > and it will return a dictionary as below: > > func(key1) = [block1:value1,block2:value4,...,blockn:value7] > > and if one block has no "key1" parameter, it will not include in this > > dict. > > > Thanks a lot! > > -- > > Coeus > > In the middle of every difficulty lies opportunity. > > ? ? ? ? ? ? ? ? -- Albert Einstein configobj is even better, very similar usage. From mdekauwe at gmail.com Mon Feb 14 05:11:35 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Mon, 14 Feb 2011 02:11:35 -0800 (PST) Subject: Class or Dictionary? References: <4d55ec65$0$29980$c3e8da3$5496439d@news.astraweb.com> <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> <090af3b8-ade9-4994-8102-cb096f67bec6@x4g2000prf.googlegroups.com> Message-ID: On Feb 14, 8:57?pm, Martin De Kauwe wrote: > On Feb 14, 8:51?pm, Dave Angel wrote: > > > > > > > On 01/-10/-28163 02:59 PM, Martin De Kauwe wrote: > > > > > > > > from other_model import OtherSubModel > > > class Model: > > > > ? ? ?def __init__(self): > > > > ? ? ? ? ?# included other external modules (i.e. in other files) > > > ? ? ? ? ?om =therSubModel() > > > > ? ? ?def run(self): > > > ? ? ? ? ?# call other submodel and pass params > > > ? ? ? ? ?om.run(params) > > > What's om supposed to be? ?You define a local variable in one method, > > and try to use it in a different one ???? > > > Perhaps you meant ?self.om = > > > ?> class OtherSubModel: > > ?> ? ? def __init__(self): > > ?> ? ? ? ? #some stuff > > ?> > > ?> ? ? def run(params): > > > You're missing a self here in the formal parameter list. > > > DaveA > > I was trying to write a smaller version of broadly what I think i am > doing, perhaps I am not implementing it correctly. I have one model > which I have coded as a class, there were a few parts which could be > used separately (sub-models). So I decided to make them separate > classes in separate files which I *thought* I could just join up into > one package at run time. This way I could also use these modules > separately. > > So in the dummy example > > the other file is imported > > from other_model import OtherSubModel > > amd om = OtherSubModel was me making an instance of it? And then when > I called the *run* part of this sub-model I was passing it the > parameter file. I am sensing I have this wrong? oh and yes i did mean self.om.run(params), sorry! From andrea.crotti.0 at gmail.com Mon Feb 14 05:33:21 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 14 Feb 2011 02:33:21 -0800 (PST) Subject: multiprocessing & more References: <373ecdcf-bb97-4f90-b291-03993fb97ce6@x11g2000yqc.googlegroups.com> Message-ID: <1d52b0b4-8d86-4e3f-b5c2-ce121e82625b@g10g2000vbv.googlegroups.com> On Feb 14, 12:14?am, Adam Skutt wrote: > On Feb 13, 12:34?pm, Andrea Crotti wrote: > > > > > First of all, does it make sense to use multiprocessing and a short > > value as boolean to check if the simulation is over or not? > > Maybe, but without knowing exactly what you're doing it's difficult to > say if any other approach would be superior. ?Plus, most of the other > approaches I can think of would require code modifications or platform- > specific assumptions. Well the other possibility that I had in mind was to spawn the very long process in an asynchronous way, but then I still have the problem to notify the rest of the program that the simulation is over. Is there a way to have an asynchronous program that also notifies when it's over easily? Otherwise I'll leave it like this it works apparently well... The only thing is that debugging (with pdb) is not so trivial, but for that I can use unit tests and check on older simulation results. > > > File I/O is inherently a concurrent, unsynchronized activity. ?A > directory listing can become stale at any time, even while the > directory listing is being built (e.g., imagine running ls or dir in a > directory where rm or del is currently executing). ?When a directory > is being modified while you're listing it, the contents of the listing > essentially become "undefined": you may get entries for files that no > longer exist, and you may not get entries for that do exist. ?A > directory listing may also return duplicate entries; this is what I > expect is happening to you. > > The right thing to do is actually check to see if all the files you > want exist, if you can. ?If not, you'll have to keep waiting until > you've opened all the files you expect to open. > > Adam Yes that would be a solution, but I can't know in the python program what file names there will be in the directory, I can only know how many will be there. So I think the easy and stupid solution is just to wait a couple of seconds and everyone is happy ;) From flebber.crue at gmail.com Mon Feb 14 06:16:52 2011 From: flebber.crue at gmail.com (flebber) Date: Mon, 14 Feb 2011 03:16:52 -0800 (PST) Subject: Call to Update All Tutorials to Python3.x Standards. References: Message-ID: On Feb 14, 11:35?am, Cameron Simpson wrote: > On 13Feb2011 14:47, rantingrick wrote: > | On Feb 13, 4:30?pm, Steven D'Aprano wrote: > > | > The official stance of the Python development team is that 2.7 and 3.x > | > will co-exist for a long, long time. Removing 2.x tutorials would be > | > cutting off our nose to spite our face. > | > | That is BS Steven and you know it! Of course we are going to support > | 2.x for a long, long, time. Heck we even have downloads available for > | Python1.x. I am talking about TUTORIALS steven, TUTORIALS! > > Steven is also talking about tutorials. Perhaps my comprehension skiils > are weak; I am basing my assrtion on his use of the word "tutorials" in > the sentence: > > ? Removing 2.x tutorials would be cutting off our nose to spite our > ? face. > > I admit my reading here may be superficial and that you may be seeing a > deeper intent. > > [...] > | [...] Stop spreading lies Steven. [...] > | PS: The only troll here is YOU! [...] > > I confess to finding these two sentences in your message contradictory. > Again, my poor comprehension skills must be to blame. > > Cheers, > -- > Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ > > That's just the sort of bloody stupid name they would choose. > ? ? ? ? - Reginald Mitchell, designer of the Spitfire Python 3 Tutorial http://docs.python.org/py3k/ Python 3 Tutorial http://diveintopython3.org/ Python 3 Video Tutorials http://www.youtube.com/results?search_query=python+3+tutorial&aq=f Python 3 Tutorial http://www.swaroopch.com/notes/Python_en:Table_of_Contents Python 3 Book http://www.amazon.com/Programming-Python-Complete-Introduction-Language/dp/0321680561/ref=sr_1_1?s=books&ie=UTF8&qid=1297682115&sr=1-1 If people want to learn there are already plenty of resources. From askutt at gmail.com Mon Feb 14 06:53:06 2011 From: askutt at gmail.com (Adam Skutt) Date: Mon, 14 Feb 2011 03:53:06 -0800 (PST) Subject: multiprocessing & more References: <373ecdcf-bb97-4f90-b291-03993fb97ce6@x11g2000yqc.googlegroups.com> <1d52b0b4-8d86-4e3f-b5c2-ce121e82625b@g10g2000vbv.googlegroups.com> Message-ID: <13ba3207-ba0c-4f00-83b1-3acb2abc5cd3@r19g2000prm.googlegroups.com> On Feb 14, 5:33?am, Andrea Crotti wrote: > Well the other possibility that I had in mind was to spawn the very > long process in an asynchronous way, but then I still have the > problem to notify the rest of the program that the simulation is over. > > Is there a way to have an asynchronous program that also notifies when > it's over easily? > Several, again, what's best depends on what you're doing: * If you can modify the application, you can have it modify that shared Value before it exits. * On UNIX, you can do a non-blocking waitpid() call to determine when the process exited. The catch is that you can only do this from an actual parent process, so you'd have to reconstruct the way you spawn processes. Plus, if you need the stdout/stderr from the process you then must also consume the I/O in an non-blocking fashion, or dedicate a thread solely to consuming the I/O. It's possible to pull similar trickery in Windows, however I don't think the standard Python library makes it convenient (the right Win32 call is GetExitCodeProcess, given a legitimate Win32 process HANDLE). * You have it write something to stdout/stderr and key off of that. Those (or slight variants on them) are the common ways. Adam From list at qtrac.plus.com Mon Feb 14 06:58:42 2011 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 14 Feb 2011 11:58:42 +0000 Subject: [python-committers] [RELEASED] Python 3.2 rc 3 In-Reply-To: <4D58CE40.1010408@python.org> References: <4D58CE40.1010408@python.org> Message-ID: <20110214115842.3c98a68e@dino> On Mon, 14 Feb 2011 07:40:00 +0100 Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm happy to announce > the third release candidate of Python 3.2. > > Python 3.2 is a continuation of the efforts to improve and stabilize > the Python 3.x line. Since the final release of Python 2.7, the 2.x > line will only receive bugfixes, and new features are developed for > 3.x only. [snip] It looks good:-) V. small suggestion: how about putting the "New, Improved, and Deprecated Modules" in What's New in alphabetical order? -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From sturlamolden at yahoo.no Mon Feb 14 06:59:30 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 14 Feb 2011 03:59:30 -0800 (PST) Subject: EPD 7.0 released References: <6a6a88a7-cbef-4b12-93e1-ba56a8cf7c0e@k9g2000yqi.googlegroups.com> Message-ID: On 14 Feb, 01:50, Robert Kern wrote: > I'd just like to jump in here to clear up this last statement as an Enthought > employee. While Enthought and its employees do contribute to the development of > numpy and scipy in various ways (and paying us money is a great way to let us do > more of it!), there is no direct relationship to the revenue we get from EPD > subscriptions and our contributions to numpy and scipy. But you do host the website, and several key NumPy and SciPy developers work for you. And NumPy and SciPy would not have reached the current maturity without Enthought. I know that you have commercial insterests in the current restructuring of NumPy (such as making it available for .NET), but it does help the development of NumPy as well. Enthought EPD also helps NumPy/SciPy indirectly, by making Python a viable alternative to Matlab: * Just having one big installer instead of 100 is why I'm allowed to use Python instead of Matlab. Others might have to use my programs, so the runtime cannot take a man year to install. * A myriad of installers is a big deterrent for any scientist considering to use Python. * Intel MKL instead of reference LAPACK (actually lapack_lite) make EPD very fast for matrix computations. * It has a 64-bit version (as opposed to only 32-bit in the "official" SciPy installer; that might have changed now.) * We don't have to know which libraries are important and/or spend time search for them. * It comes with C, C++ and Fortran compilers (GCC) preconfigured to work with distutils, link correctly, etc. Sturla From cjwilliams43 at gmail.com Mon Feb 14 07:35:59 2011 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Mon, 14 Feb 2011 07:35:59 -0500 Subject: EPD 7.0 released In-Reply-To: References: <6a6a88a7-cbef-4b12-93e1-ba56a8cf7c0e@k9g2000yqi.googlegroups.com> Message-ID: <4D5921AF.9030302@gmail.com> On 14-Feb-11 06:59 AM, sturlamolden wrote: > On 14 Feb, 01:50, Robert Kern wrote: > >> I'd just like to jump in here to clear up this last statement as an Enthought >> employee. While Enthought and its employees do contribute to the development of >> numpy and scipy in various ways (and paying us money is a great way to let us do >> more of it!), there is no direct relationship to the revenue we get from EPD >> subscriptions and our contributions to numpy and scipy. > > But you do host the website, and several key NumPy and SciPy > developers work for you. And NumPy and SciPy would not have reached > the current maturity without Enthought. I know that you have > commercial insterests in the current restructuring of NumPy (such as > making it available for .NET), but it does help the development of > NumPy as well. > > Enthought EPD also helps NumPy/SciPy indirectly, by making Python a > viable alternative to Matlab: > > * Just having one big installer instead of 100 is why I'm allowed to > use Python instead of Matlab. Others might have to use my programs, so > the runtime cannot take a man year to install. > > * A myriad of installers is a big deterrent for any scientist > considering to use Python. > > * Intel MKL instead of reference LAPACK (actually lapack_lite) make > EPD very fast for matrix computations. > > * It has a 64-bit version (as opposed to only 32-bit in the "official" > SciPy installer; that might have changed now.) > > * We don't have to know which libraries are important and/or spend > time search for them. > > * It comes with C, C++ and Fortran compilers (GCC) preconfigured to > work with distutils, link correctly, etc. > > > Sturla > > The purchase price for what, until now, has been open source and free seems high. Colin W From karim.liateni at free.fr Mon Feb 14 07:41:49 2011 From: karim.liateni at free.fr (Karim) Date: Mon, 14 Feb 2011 13:41:49 +0100 Subject: [Tutor] Accessing query results html frame : PLEASE READ ME :o) In-Reply-To: <4D54EA92.4030800@free.fr> References: <4D542AA0.5080801@free.fr> <4D54EA92.4030800@free.fr> Message-ID: <4D59230D.1030502@free.fr> Hello, As I get no response from the tutor python list, I am continuing to investigate my problem. In fact the issue is that there are 2 forms in the interactive page and my request does nothing instead I get the interactive page not the submission I asked (query results). The 2 forms are: 1.
2. And the parameters for each are: 1)           2) And I recall my data of the progam below: data = { 'init' : "", 'LastForm': "SavedQuery", 'prompted': "yes", 'class': "Development", 'personalQuery': "DKPV", 'REMOTE_USER': username, 'QS': " -p DKPVALIDATION_PLUGIN \(Class 'isequal' "Development" \)", 'use_field_defs':"false", 'QueryName': "DKPV", 'QueryType': "personal", 'ACTION': "Query" } So the question is how could I specify the correct FORM submission and how could I chose the correct action because there are several TYPE='submit' and I am only interested by this one VALUE="Query"? Regards Karim On 02/11/2011 08:51 AM, Karim wrote: > > Hello, > > In fact as found in the net: > > "The concept of browser frames is completely outside the scope of > HTTP. However, browser frames are defined in HTML, and so is the > target property on form elements: <form action="/somescript?x=y" > method="POST" target="_top"> This will make the form submit to the > _top frame, which means "use the full browser window" " > > That means that my post form: > > ENCTYPE="application/x-www-form-urlencoded" TARGET="rightframe"> > > has a target property to make the submit to the 'rightframe'. > > Any ideas how I can modified the code (I think the request data or > whatever) below to access without knowing the temporary html file name > generically. > > Regards > Karim > > On 02/10/2011 07:12 PM, Karim wrote: >> >> Hello All, >> >> I get from Steven an very useful link (void space) for http >> authentication. I added some codes to be >> able to POST FORM a query as I do it by clicking a query button to >> get a list of bug Id on a server. >> The problem is I get a html page which refers 2 frames. And I am >> interesting in one particular frame >> namely for example, >> http://{server}:{port}/wt/tmp/results:karim.liateni.31_3917.html'.format(server=server, >> port=port). >> But this pages is created every times in a tmp directory each time >> with a different name. >> >> 1) How can I get the name of this page because with python the page >> resulting of my query is not mentionned (hidden like)? >> Interactively there are 3 frames but only this one is of interest for >> me. But no name of this page is visible in the main html page. >> Is there a method to get all the nested frames locations? >> >> 2) I can see this page interactively when I click on a submit query >> button. Do I need to add 'ACTION': "Query" > in the query dictionnary to simulate a click for submission >> (type="submit" button) ? >> >> 3) Interactively I see that cgi arg NextForm is empty so I let it >> like that in my query and LastForm was set to "SavedQuery". I put the >> same value in my python code. Is this ok? >> >> import urllib >> import urllib2 >> >> server='dummy.com' >> port='8081' >> >> username = 'karim.liateni' >> password = 'dummy_pass' >> >> theurl = >> 'http://{server}:{port}/ddts/ddts_main'.format(server=server, port=port) >> #theurl = >> 'http://{server}:{port}:8081/wt/tmp/results:karim.liateni.31_3917.html'.format(server=server, >> port=port) >> >> #MEMO: >> #> ENCTYPE="application/x-www-form-urlencoded" TARGET="rightframe"> >> >> data = { >> 'NextForm': "", >> 'LastForm': "SavedQuery", >> 'prompted': "yes", >> 'class': "Development", >> 'personalQuery': "DKPV", >> 'REMOTE_USER': username, >> 'QS': " -p DKPVALIDATION_PLUGIN \(Class 'isequal' >> "Development" \)", >> 'use_field_defs':"false", >> 'QueryName': "DKPV", >> 'QueryType': "personal", >> 'ACTION': "Query" >> } >> >> query = urllib.urlencode(data) >> request = urllib2.Request(theurl, query) >> >> passman = urllib2.HTTPPasswordMgrWithDefaultRealm() >> passman.add_password(None, theurl, username, password) >> authhandler = urllib2.HTTPBasicAuthHandler(passman) >> >> opener = urllib2.build_opener(authhandler) >> urllib2.install_opener(opener) >> >> pagehandle = urllib2.urlopen(request) >> print(pagehandle.read()) >> _______________________________________________ >> Tutor maillist - Tutor at python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdekauwe at gmail.com Mon Feb 14 07:48:49 2011 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Mon, 14 Feb 2011 04:48:49 -0800 (PST) Subject: Class or Dictionary? References: <9762f7f1-6a92-4a98-89b9-57a87f23707c@n36g2000pre.googlegroups.com> <8891c874-d8f7-47d8-bcf6-77993c6e00eb@l12g2000pra.googlegroups.com> <5696bec7-9c16-4cd5-a1a7-6ff3520b6333@r19g2000prm.googlegroups.com> <090af3b8-ade9-4994-8102-cb096f67bec6@x4g2000prf.googlegroups.com> Message-ID: <6e44a4e7-4b3f-4d2c-a401-1281ac1656fa@y30g2000prf.googlegroups.com> I managed to get it to work like it explained, apologies not sure what I did wrong earlier, odd. Anyway thanks a lot for all of the suggestions + help From sturlamolden at yahoo.no Mon Feb 14 08:23:22 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 14 Feb 2011 05:23:22 -0800 (PST) Subject: EPD 7.0 released References: <6a6a88a7-cbef-4b12-93e1-ba56a8cf7c0e@k9g2000yqi.googlegroups.com> <4D5921AF.9030302@gmail.com> Message-ID: On 14 Feb, 13:35, "Colin J. Williams" wrote: > The purchase price for what, until now, has been open source and free > seems high. The price is not high compared to other tools scientists are using, e.g. Matlab and S-PLUS. If you consider to buy an MKL license from Intel only to build NumPy and SciPy against "Intel Math Kernel Library" (MKL), EPD is a less expensive option. You can get NumPy and SciPy built against MKL from Enthought for less than the price of an MKL license -- MKL is $399, EPD is $199. And on top of being cheaper, it saves us all the work building and installing. How much do you value your own time? Is the price high compared to the time spent "doing it yourself"? How long does it take to configure and build ATLAS on Windows, build NumPy and SciPy against ATLAS, and then build Matplotlib against the ATLAS dependent NumPy? Have you seen the number of posts on NumPy and SciPy mailing lists from people going insane trying to build the libraries? Do you still think EPD is expensive? The libraries in EPS (except MKL) is still open source and free if you want to mess with 100s of installers and/or build scripts. Sturla From ll.snark at gmail.com Mon Feb 14 09:07:46 2011 From: ll.snark at gmail.com (LL.Snark) Date: Mon, 14 Feb 2011 15:07:46 +0100 Subject: Arrays/List, filters, Pytho, Ruby In-Reply-To: References: <4d55a9b5$0$19686$426a34cc@news.free.fr> Message-ID: <4d5937e6$0$27544$426a74cc@news.free.fr> On 12/02/2011 04:49, Terry Reedy wrote: > On 2/11/2011 4:24 PM, LL.Snark wrote: >> Hi, >> >> I'm looking for a pythonic way to translate this short Ruby code : >> t=[6,7,8,6,7,9,8,4,3,6,7] >> i=t.index {|x| x> >> If you don't know Ruby, the second line means : > > What does Ruby do if there is no such element? > For Python, the answer should be either None or ValueError. Ruby code : # What is the index, in array t, # of the first element x such that x 8 # Raises an exception if no value found ====================================================== The following solutions raise a StopIteration exception if no value is found. See below how to use the second argument of next next(filter(lambda x: x[1] (8,4) from itertools import dropwhile next(dropwhile(lambda x: x[1]>=t[0],enumerate(t))) => (8,4) Or if you don't like enumerate : next(filter(lambda x: x 4 t.index(next(filter(lambda x: x 8 next(filter(t[0].__gt__, t)) => 4 ================================================================ Generators and enumerate : next(i for i,v in enumerate(t) if v 8 If no values exists, this raises an exception. Second argument of next can help you : next((i for i,v in enumerate(t) if v 8 # returns None if no value found =========================================================== If you use lists instead of generators, it works, but you have to go across the whole array : [x 8 [i for i,v in enumerate(t) if v < t[0]] => [ 8, 9 ] (indices of all array values less than t[0] If you are only interested in the first value : [i for i,v in enumerate(t) if v < t[0]][0] => 8 (but raises an exception if the list if no value is found) [i for i,v in enumerate(t) if v < t[0]][0:1] => [8] (return an empty list if no value is found) Keep in mind that, even if you just select the first value [0] or [0:1], you go across the whole array t ================================================= I found it very interesting to read all these short lines of code. Thanks to : Chris, Ian, Paul, Jon, Therry, Bruno, Arnaud and people that have no name (like me...) next(((i,v) for i,v in enumerate(t) if v Dear Python folks, Those of you whose duties include teaching basic stats might be interested in these interactive tutorial files, designed to illustrate basic concepts. Running the code opens up an interactive figure window. When you click on a figure to add new points, the statistical tests shown in the figure change accordingly. http://www.dartmouth.edu/~raj/intro-stats.html The code has lots of comments in it, which attempt to explain the concepts as explicitly as possible. No prior knowledge of Python or statistics is assumed. These programs require the SciPy and Matplotlib modules. The tutorials are: - interactive_mean_std_normal_distribution.py - interactive_one_sample_t_test.py - interactive_two_sample_t_test.py - interactive_correlation_plot.py The same webpage also contains Matlab versions of the scripts. Please feel more than free to use any of the code for teaching, if you find it useful. Yours, Rajeev Raizada Research Assistant Professor Neukom Institute for Computational Science Dartmouth College HB 6255 Hanover NH 03755 Tel: 603 646 0175 E.mail: rajeev.raizada at dartmouth.edu WWW: http://www.dartmouth.edu/~raj From allbory.dan at gmail.com Mon Feb 14 10:51:39 2011 From: allbory.dan at gmail.com (Dan Lee) Date: Mon, 14 Feb 2011 07:51:39 -0800 (PST) Subject: How to run another python script? Message-ID: <1ce97808-22d0-4ff8-b75d-2a57dd1958b8@o39g2000prb.googlegroups.com> Hi. I just knew what python is. Now I'm about to write backup script.Now I got 2 scripts. AAA : generate zip file BBB : delete old file. AAA is done. Now I'm going to code BBB file. and I will fix AAA to call BBB to delete dump file at the end. Please let me know How can I call the BBB file from AAA file. Thanks in advance. Dan From rantingrick at gmail.com Mon Feb 14 10:56:53 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 14 Feb 2011 07:56:53 -0800 (PST) Subject: How to run another python script? References: <1ce97808-22d0-4ff8-b75d-2a57dd1958b8@o39g2000prb.googlegroups.com> Message-ID: On Feb 14, 9:51?am, Dan Lee wrote: > AAA : generate zip file > BBB : delete old file. > > AAA is done. > Now I'm going to code BBB file. and I will fix AAA to call BBB to > delete dump file at the end. > Please let me know How can I call the BBB file from AAA file. Simple: Make a call using the underlying os from the aptly named "os" module (or other!). OR import BBB and execute the code. From rantingrick at gmail.com Mon Feb 14 11:03:27 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 14 Feb 2011 08:03:27 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 13, 10:39?pm, Christian Heimes wrote: > Am 14.02.2011 00:12, schrieb rantingrick: > > > False! There IS harm in using super when super not needed. The > > difference is readability! And don't downplay that aspect. You > > yourself have said this in the past. It seems *some* of us have very > > short memories. > > Of course you are entitled to have your own opinion and own coding > style. You are also allowed to disregard the opinion of experienced > Python developers, who really know what they are talking about. But > please DO NOT teach new Python users wrong coding! I assume Benjamin > will follow the right lead here. And which "lead" is the correct lead to follow? And more importantly WHY? You failed to offer any substance to your comments. They left myself (and many others) wanting. > If you have a short memory then you should definitely use one way -- the > correct way for all cases -- to call the parent's class init method. Again WHAT IS the correct way? We've heard your opinion now let's hear some fact based arguments. > Otherwise your future self is going to hate your current self for > introducing potential buggy code. Where is the buggy code? Show me how Ship.__init__() can break. Anyone can argue, few can offer facts. If you bring an argument that Ship.__init__() can break if someone changes the code then that IS NOT an valid argument. ANY code can be broken with the addition or subtraction of a single char. From mauro.caceres at gmail.com Mon Feb 14 11:18:33 2011 From: mauro.caceres at gmail.com (Mauro Caceres) Date: Mon, 14 Feb 2011 13:18:33 -0300 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: > > > Where is the buggy code? Show me how Ship.__init__() can break. Anyone > can argue, few can offer facts. If you bring an argument that > Ship.__init__() can break if someone changes the code then that IS NOT > an valid argument. ANY code can be broken with the addition or > subtraction of a single char. > > The idea of using super() is that it works with single inheritance and multiple inheritance. If after a while your FasterShip extends from Ship and Bird, your Ship.__init__() will still work BUT it may not be calling the right code. So using super() is less error prone. The official documentation also recommends to use super() http://docs.python.org/library/functions.html#super -- Mauro C?ceres -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Feb 14 11:29:00 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Feb 2011 09:29:00 -0700 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Feb 13, 2011 at 9:39 PM, Christian Heimes wrote: > If you have a short memory then you should definitely use one way -- the > correct way for all cases -- to call the parent's class init method. > Otherwise your future self is going to hate your current self for > introducing potential buggy code. Unfortunately, there is no "correct way for all cases". See: http://fuhm.net/super-harmful/ From tdldev at gmail.com Mon Feb 14 12:10:35 2011 From: tdldev at gmail.com (Verde Denim) Date: Mon, 14 Feb 2011 12:10:35 -0500 Subject: encoding Message-ID: All I'm a bit new to py coding and need to setup some code to encode/decode base 128. Anyone here have some info they can point me to do get this done? I've been looking around on the web for a few days and can't seem to lay my hands on anything definitive. Thanks in advance for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Mon Feb 14 12:30:00 2011 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 14 Feb 2011 11:30:00 -0600 Subject: EPD 7.0 released In-Reply-To: References: <6a6a88a7-cbef-4b12-93e1-ba56a8cf7c0e@k9g2000yqi.googlegroups.com> Message-ID: On 2/14/11 5:59 AM, sturlamolden wrote: > On 14 Feb, 01:50, Robert Kern wrote: > >> I'd just like to jump in here to clear up this last statement as an Enthought >> employee. While Enthought and its employees do contribute to the development of >> numpy and scipy in various ways (and paying us money is a great way to let us do >> more of it!), there is no direct relationship to the revenue we get from EPD >> subscriptions and our contributions to numpy and scipy. > > But you do host the website, and several key NumPy and SciPy > developers work for you. And NumPy and SciPy would not have reached > the current maturity without Enthought. I know that you have > commercial insterests in the current restructuring of NumPy (such as > making it available for .NET), but it does help the development of > NumPy as well. I just don't want people to get the impression that we are distributing the proceeds from EPD sales to numpy developers in general or that purchasing EPD is equivalent to donating to the numpy and scipy projects. If people want to do that, there are plenty of grad student developers who would be happy to take your money to work on numpy and scipy for a day or two. That's a more efficient use of your money. :-) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From ian.g.kelly at gmail.com Mon Feb 14 12:35:33 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Feb 2011 10:35:33 -0700 Subject: encoding In-Reply-To: References: Message-ID: On Mon, Feb 14, 2011 at 10:10 AM, Verde Denim wrote: > All > I'm a bit new to py coding and need to setup some code to encode/decode base > 128. > Anyone here have some info they can point me to do get this done? I've been > looking around on the web for a few days and can't seem to lay my hands on > anything definitive. > Thanks in advance for your help. First, why do you want to do this? I ask because there is probably a better way to achieve what you want. I'm not aware of a standard for "base 128", and it does not sound to me like something that would be very useful. Base 64 is commonly used as an encoding system because it fits inside the 94 printable characters of ASCII and is easily implemented. It is also provided by the Python standard library. Why not use this instead? Cheers, Ian From python at mrabarnett.plus.com Mon Feb 14 12:46:01 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 14 Feb 2011 17:46:01 +0000 Subject: encoding In-Reply-To: References: Message-ID: <4D596A59.6030905@mrabarnett.plus.com> On 14/02/2011 17:10, Verde Denim wrote: > All > I'm a bit new to py coding and need to setup some code to encode/decode > base 128. > Anyone here have some info they can point me to do get this done? I've > been looking around on the web for a few days and can't seem to lay my > hands on anything definitive. > Thanks in advance for your help. > http://en.wikipedia.org/wiki/LEB128 From sparks.m at gmail.com Mon Feb 14 12:55:01 2011 From: sparks.m at gmail.com (Michael Sparks) Date: Mon, 14 Feb 2011 09:55:01 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: It can be broken if someone tries to use the class as is - that is treating the class as a model - to drive a display of the ship. If it was written using super() then that wouldn't be a problem. For example, I could write a display mixin that I'd like to use like this: class VisibleShip(ship, sprite): ... and class FasterVisibleShip(faster_ship, sprite): ... But because neither ship nor faster_ship call their super class correctly, this won't work. To turn this into something concrete, consider the following code: class mixin(object): """ The key benefit of this mixin is that it tracks instances created and also allows subclasses to have inheritable default values. """ objects = [] def __init__(self, **kwargs): super(mixin, self).__init__() self.__dict__.update(**kwargs) self.objects.append(self) Using that code, I can create my ship model as a mixin: class ship(mixin): x = 0 y = 0 step = 1 angle = 0 name = "" def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step self.y = self.y + math.sin(math.radians(self.angle)) * self.step As well as the faster ship: class fastership(ship): speed = 1 def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step * self.speed self.y = self.y + math.sin(math.radians(self.angle)) * self.step * self.speed I can then create a sprite mixin: class sprite(mixin): x = 0 y = 0 image = "sprite.png" display = None def __init__(self, **kwargs): super(sprite, self).__init__(**kwargs) self._image = pygame.image.load(self.image) print "Image Loaded", self.__class__ def render(self,surface): # assume surface is something like a pygame surface surface.blit(self._image, (self.x, self.y)) And also for debug purposes a debug mixin: import time class debug(mixin): debug_file = "debug.log" debug_handle = None def __init__(self, **kwargs): print "Creation arguments", self.__class__, kwargs super(debug, self).__init__(**kwargs) @classmethod def dump_state(klass,self): if klass.debug_handle is None: klass.debug_handle = open(self.debug_file, "w") klass.debug_handle.write(str(time.time()) + ":" + str(klass) + ":" + str(self.__dict__)+"\n\n") klass.debug_handle.flush() Using these we can create visible ships which can also send debug information to a file when they're pinged: class VisibleShip(ship, sprite, debug): x = 300 y = 300 image = "ship.png" class FasterVisibleShip(fastership, sprite, debug): x = 400 y = 400 image = "fastship.png" And use them like this: import pygame pygame.init() display = pygame.display.set_mode((800, 600), 0) ship_one = VisibleShip(step=1) ship_two = FasterVisibleShip(angle = 60) t = time.time() while time.time()-t <1 : display.fill((0,0,0)) for sprite in mixin.objects: sprite.render(display) sprite.dump_state(sprite) sprite.update() pygame.display.flip() time.sleep(0.05) Now, you could do this the other way I mentioned by by using kwargs, and super in this way you can get the various classes to play nicely with each other, which means you can have clearer code. After all, our ship / fastership have now become focussed on the code you want them to model - not on faff with superclasses: class ship(mixin): x = 0 y = 0 step = 1 angle = 0 name = "" def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step self.y = self.y + math.sin(math.radians(self.angle)) * self.step class fastership(ship): speed = 1 def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step * self.speed self.y = self.y + math.sin(math.radians(self.angle)) * self.step * self.speed But not only that they play nicely with debug code and also display code, and you get defaults you can inherit at the same time too. If you wrote ship / fastership with an explicit init and didn't do the super() call - eg like this: class ship(object): def __init__(self,x=0,y=0,step=1,angle=0, name=''): self.x = x self.y = y self.step = step self.angle = angle self.name = name def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step self.y = self.y + math.sin(math.radians(self.angle)) * self.step class fastership(ship): def __init__(self,speed=1): ship.__init__(self,x=0,y=0,step=1,angle=0, name='') self.speed = speed def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step * self.speed self.y = self.y + math.sin(math.radians(self.angle)) * self.step * self.speed and mixed in like this: class VisibleShip(ship, sprite): image = "ship.png" class FasterVisibleShip(fastership, sprite): image = "fastship.png" Then the code breaks - simply because you're doing this: ship.__init__(self,x=0,y=0,step=1,angle=0, name='') rather than: super(ship,self).__init__() and super(fastership,self).__init__() At the end of the day, both approaches *work* but to differing levels and differing levels of flexibility & maintainability. >From the perspective of fragility though this approach is far more fragile: ship.__init__(self,x=0,y=0,step=1,angle=0, name='') For convenience I'm copying below my .sig the code I mention above, for you to make your own mind up which you find more maintainable. (Consider extending sprite handling, or the complexity of the ship model) Michael. -- http://www.kamaelia.org/Home , http://twitter.com/kamaelian #!/usr/bin/python class mixin(object): """ The key benefit of this mixin is that it tracks instances created and also allows subclasses to have inheritable default values. """ objects = [] def __init__(self, **kwargs): super(mixin, self).__init__() self.__dict__.update(**kwargs) self.objects.append(self) import math class ship(mixin): x = 0 y = 0 step = 1 angle = 0 name = "" def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step self.y = self.y + math.sin(math.radians(self.angle)) * self.step class fastership(ship): speed = 1 def update(self): self.x = self.x + math.cos(math.radians(self.angle)) * self.step * self.speed self.y = self.y + math.sin(math.radians(self.angle)) * self.step * self.speed class sprite(mixin): x = 0 y = 0 image = "sprite.png" display = None def __init__(self, **kwargs): super(sprite, self).__init__(**kwargs) self._image = pygame.image.load(self.image) print "Image Loaded", self.__class__ def render(self,surface): # assume surface is something like a pygame surface surface.blit(self._image, (self.x, self.y)) import time class debug(mixin): "Not perfect at all IMO" debug_file = "debug.log" debug_handle = None def __init__(self, **kwargs): print "Creation arguments", self.__class__, kwargs super(debug, self).__init__(**kwargs) @classmethod def dump_state(klass,self): if klass.debug_handle is None: klass.debug_handle = open(self.debug_file, "w") klass.debug_handle.write(str(time.time()) + ":" + str(klass) + ":" + str(self.__dict__)+"\n\n") klass.debug_handle.flush() class VisibleShip(ship, sprite, debug): x = 300 y = 300 image = "ship.png" class FasterVisibleShip(fastership, sprite, debug): x = 400 y = 400 image = "fastship.png" import pygame pygame.init() display = pygame.display.set_mode((800, 600), 0) ship_one = VisibleShip(step=1) ship_two = FasterVisibleShip(angle = 60) t = time.time() while time.time()-t <1 : display.fill((0,0,0)) for sprite in mixin.objects: sprite.render(display) sprite.dump_state(sprite) sprite.update() pygame.display.flip() time.sleep(0.05) From tdldev at gmail.com Mon Feb 14 13:00:33 2011 From: tdldev at gmail.com (Verde Denim) Date: Mon, 14 Feb 2011 13:00:33 -0500 Subject: encoding In-Reply-To: References: Message-ID: On Mon, Feb 14, 2011 at 12:35 PM, Ian Kelly wrote: > On Mon, Feb 14, 2011 at 10:10 AM, Verde Denim wrote: > > All > > I'm a bit new to py coding and need to setup some code to encode/decode > base > > 128. > > Anyone here have some info they can point me to do get this done? I've > been > > looking around on the web for a few days and can't seem to lay my hands > on > > anything definitive. > > Thanks in advance for your help. > > First, why do you want to do this? I ask because there is probably a > better way to achieve what you want. I'm not aware of a standard for > "base 128", and it does not sound to me like something that would be > very useful. > > Base 64 is commonly used as an encoding system because it fits inside > the 94 printable characters of ASCII and is easily implemented. It is > also provided by the Python standard library. Why not use this > instead? > > Cheers, > Ian > Ian Thanks for the reply. The fact is that I don't _want_ to, but need to as a part of a work project. If I had a choice, base 64 would be the way to go since (as you point out), it's already in the standard library. If I could take the encoded form and translate it to base 64 and then use the standard library, that would work as well, but I'm not sure that there's a one-to-one correlation there. - Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From sridharr at activestate.com Mon Feb 14 13:02:50 2011 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 14 Feb 2011 10:02:50 -0800 Subject: ANN: ActivePython 2.7.1.4 is now available Message-ID: <4D596E4A.1000405@activestate.com> ActiveState is pleased to announce ActivePython 2.7.1.4, a complete, ready-to-install binary distribution of Python 2.7. http://www.activestate.com/activepython/downloads What's New in ActivePython-2.7.1.4 ================================== *Release date: 14-Feb-2011* New Features & Upgrades ----------------------- - Upgrade to PyPM 1.3.1: - Programmatic use via ``pypm.cmd(['install', 'foo'])`` - Support for postinstall and conditional user-notes - Upgraded the following packages: - SQLAlchemy-0.6.6 Noteworthy Changes & Bug Fixes ------------------------------ - PyPM bug fixes: - Bug #88791: fail immediately for missing dependencies - Fix needless truncation of output when piping (eg: ``pypm list | less``) - Respect download cache of ``*.pypm`` packages (don't redownload) What is ActivePython? ===================== ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Solaris, HP-UX and AIX builds, and access to older versions are available in ActivePython Business, Enterprise and OEM editions: http://www.activestate.com/python ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. ActivePython also includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: C:\>pypm install mysql-python [...] C:\>python >>> import MySQLdb >>> See this page for full details: http://docs.activestate.com/activepython/2.7/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.7/ We would welcome any and all feedback to: activepython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/enter_bug.cgi?product=ActivePython Supported Platforms =================== ActivePython is available for the following platforms: - Windows (x86 and x64) - Mac OS X (x86 and x86_64; 10.5+) - Linux (x86 and x86_64) - Solaris/SPARC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) - Solaris/x86 (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/PA-RISC (32-bit) (Business, Enterprise or OEM edition only) - HP-UX/IA-64 (32-bit and 64-bit) (Enterprise or OEM edition only) - AIX/PowerPC (32-bit and 64-bit) (Business, Enterprise or OEM edition only) More information about the Business Edition can be found here: http://www.activestate.com/business-edition Custom builds are available in the Enterprise Edition: http://www.activestate.com/enterprise-edition Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From tdldev at gmail.com Mon Feb 14 13:03:24 2011 From: tdldev at gmail.com (Verde Denim) Date: Mon, 14 Feb 2011 13:03:24 -0500 Subject: encoding In-Reply-To: <4D596A59.6030905@mrabarnett.plus.com> References: <4D596A59.6030905@mrabarnett.plus.com> Message-ID: On Mon, Feb 14, 2011 at 12:46 PM, MRAB wrote: > On 14/02/2011 17:10, Verde Denim wrote: > >> All >> I'm a bit new to py coding and need to setup some code to encode/decode >> base 128. >> Anyone here have some info they can point me to do get this done? I've >> been looking around on the web for a few days and can't seem to lay my >> hands on anything definitive. >> Thanks in advance for your help. >> >> http://en.wikipedia.org/wiki/LEB128 > -- > > MRAB Thanks for the reply. The link you sent will (hopefully) give me a starting point. Do you know if there are particular implementations of base 128 encoding that differ from LEB? - Jack -------------- next part -------------- An HTML attachment was scrubbed... URL: From nomail at please.com Mon Feb 14 13:38:54 2011 From: nomail at please.com (Sven) Date: Mon, 14 Feb 2011 12:38:54 -0600 Subject: How to run another python script? References: <1ce97808-22d0-4ff8-b75d-2a57dd1958b8@o39g2000prb.googlegroups.com> Message-ID: On Mon, 14 Feb 2011 07:56:53 -0800, rantingrick wrote: > On Feb 14, 9:51?am, Dan Lee wrote: > >> AAA : generate zip file >> BBB : delete old file. >> >> AAA is done. >> Now I'm going to code BBB file. and I will fix AAA to call BBB to >> delete dump file at the end. >> Please let me know How can I call the BBB file from AAA file. > > Simple: Make a call using the underlying os from the aptly named "os" > module (or other!). OR import BBB and execute the code. I would however recommend using the subprocess module instead of the os module. http://docs.python.org/library/subprocess.html -- ./Sven From jeanmichel at sequans.com Mon Feb 14 13:55:32 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 14 Feb 2011 19:55:32 +0100 Subject: How to run another python script? In-Reply-To: <1ce97808-22d0-4ff8-b75d-2a57dd1958b8@o39g2000prb.googlegroups.com> References: <1ce97808-22d0-4ff8-b75d-2a57dd1958b8@o39g2000prb.googlegroups.com> Message-ID: <4D597AA4.9000601@sequans.com> Dan Lee wrote: > Hi. > > I just knew what python is. > Now I'm about to write backup script.Now I got 2 scripts. > > AAA : generate zip file > BBB : delete old file. > > AAA is done. > Now I'm going to code BBB file. and I will fix AAA to call BBB to > delete dump file at the end. > Please let me know How can I call the BBB file from AAA file. > > Thanks in advance. > Dan > In that case, code the delete function in AAA => No BBB file, problem solved. There is of course plenty of ways to execute BBB from AAA but that would be overkill. If you really want to write the BBB file, then write it, import it in AAA and call the BBB.deleteOldFile function. JM From python at mrabarnett.plus.com Mon Feb 14 13:58:45 2011 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 14 Feb 2011 18:58:45 +0000 Subject: encoding In-Reply-To: References: <4D596A59.6030905@mrabarnett.plus.com> Message-ID: <4D597B65.4080505@mrabarnett.plus.com> On 14/02/2011 18:03, Verde Denim wrote: > > > On Mon, Feb 14, 2011 at 12:46 PM, MRAB > wrote: > > On 14/02/2011 17:10, Verde Denim wrote: > > All > I'm a bit new to py coding and need to setup some code to > encode/decode > base 128. > Anyone here have some info they can point me to do get this > done? I've > been looking around on the web for a few days and can't seem to > lay my > hands on anything definitive. > Thanks in advance for your help. > > http://en.wikipedia.org/wiki/LEB128 > -- > > MRAB > Thanks for the reply. The link you sent will (hopefully) give me a > starting point. Do you know if there are particular implementations of > base 128 encoding that differ from LEB? > I don't know anything more about it. Implementing it should be very easy; it's a very simple encoding. From rantingrick at gmail.com Mon Feb 14 14:15:59 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 14 Feb 2011 11:15:59 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 14, 11:55?am, Michael Sparks wrote: > It can be broken if someone tries to use the class as is - that is > treating the class as a model - to drive a display of the ship. If > it was written using super() then that wouldn't be a problem. > > For example, I could write a display mixin that I'd like to use like > this: [snip: miles of code not formatted for 79 chars!] That was a nice long winded example of how to break code by using it in an improper manner. You could have just called the base with one too many arguments and achieved the same. However the developer would be suffering from either; severe memory loss and/or lack of reading comprehension if he tried to use -a- his class interface in a manner that it was not originally intended. I could likewise use a hammer to drive screws and then rant and rave later how the hammer is insufficient. Surely my methods could not be a fault, surely? ;-) From awilliam at whitemice.org Mon Feb 14 14:19:32 2011 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 14 Feb 2011 14:19:32 -0500 Subject: encoding In-Reply-To: References: <4D596A59.6030905@mrabarnett.plus.com> Message-ID: <1297711172.7734.2.camel@linux-yu4c.site> On Mon, 2011-02-14 at 13:03 -0500, Verde Denim wrote: > On Mon, Feb 14, 2011 at 12:46 PM, MRAB > wrote: > On 14/02/2011 17:10, Verde Denim wrote: > All > I'm a bit new to py coding and need to setup some code to > encode/decode > base 128. > Anyone here have some info they can point me to do get thdone? I've > been looking around on the web for a few days and can't seetlay my > hands on anything definitive. > Thanks in advance for your help. > http://en.wikipedia.org/wiki/LEB128 > Thanks for the reply. The link you sent will (hopefully) give me a > starting point. Do you know if there are particular implementations of > base 128 encoding that differ from LEB? The ULEB128Adapter class @ < https://bitbucket.org/cmcqueen1975/pythondwarf/src/f2ffeabfa2a6/dwarf32.py> ??? class ULEB128Adapter(Adapter): """ Adapter for DWARF unsigned LEB128. """ def _encode(self, obj, context): obj2 = [] value = int(obj) while True: byte = value & 0x7F value >>= 7 if value != 0: byte = byte | 0x80 obj2.append(chr(byte)) if value == 0: break return obj2 def _decode(self, obj, context): value = 0 for b in reversed(obj): value = value * 128 + (ord(b) & 0x7F) return value From drsalists at gmail.com Mon Feb 14 14:25:00 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 14 Feb 2011 11:25:00 -0800 Subject: How to create a dict based on such a file? In-Reply-To: References: Message-ID: On Sun, Feb 13, 2011 at 9:47 PM, Wang Coeus wrote: > Hi all, > I am new to python. Currently I encountered a problem, please help me to > solve this. Thanks in advance! > I have a file like below: > ++++++++++++++++++++++++++++++++++++++ > block1 > { > ?key1=value1 > ?key2=value2 > ?key3=value3 > } > block2 > { > ?key1=value4 > ?key2=value5 > ?key4=value6 > } > ... > blockn > { > ?key1=value7 > ?key2=value8 > ?keyn=valuen > } > +++++++++++++++++++++++++++++++++++++++ > Different block may have different keys and even same key in different > blocks may have different values. > > Now I want to get a function, which like this: > func(key) > and it will return a dictionary as below: > func(key1) = [block1:value1,block2:value4,...,blockn:value7] > and if one block has no "key1" parameter, it will not include in this > dict. > > Thanks a lot! pyparsing should be able to make pretty short work of exactly the format you want. FWIW, the creator of the many .ini format(s), Microsoft, no longer recommends using .ini files. From sparks.m at gmail.com Mon Feb 14 14:45:10 2011 From: sparks.m at gmail.com (Michael Sparks) Date: Mon, 14 Feb 2011 11:45:10 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 14, 7:15?pm, rantingrick wrote: > On Feb 14, 11:55?am, Michael Sparks wrote: > > > It can be broken if someone tries to use the class as is - that is > > treating the class as a model - to drive a display of the ship. If > > it was written using super() then that wouldn't be a problem. > > > For example, I could write a display mixin that I'd like to use like > > this: > > [snip: miles of code not formatted for 79 chars!] Core code recopied into a pastebin instead, if that's your only problem. * http://pastebin.com/nuaafqSE I hardly call 87 lines of code "miles of code" though myself. I call it a relatively trivial example aimed at showing the benefit of using super() in your code rather than hard coding brittle fragility into your code. > That was a nice long winded example of how to break code by using it > in an improper manner. No, it was a thought out example of how writing code slightly differently from how you do now can result in something more practical, reusable, extendable, and maintainable. I was hoping to educate you as to why one approach *might* be considered better than another. Deriding is as you do completely misses the point, sadly. Michael. From sohel807 at gmail.com Mon Feb 14 16:02:25 2011 From: sohel807 at gmail.com (Akand Islam) Date: Mon, 14 Feb 2011 13:02:25 -0800 (PST) Subject: Non-linear regression help in Python Message-ID: <963b83e6-ea51-4c36-b212-0deeef657630@o32g2000prb.googlegroups.com> Hello all, I want to do non-linear regression by fitting the model (let say, y = a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must be in between (0 to 1), and others can be of any values. How can I perform my job in python? Thanks in advance. -- Akand From krzysztof.t.bieniasz at gmail.com Mon Feb 14 16:24:51 2011 From: krzysztof.t.bieniasz at gmail.com (Krzysztof Bieniasz) Date: Mon, 14 Feb 2011 21:24:51 +0000 (UTC) Subject: Non-linear regression help in Python References: <963b83e6-ea51-4c36-b212-0deeef657630@o32g2000prb.googlegroups.com> Message-ID: Dnia Mon, 14 Feb 2011 13:02:25 -0800, Akand Islam napisa?(a): > Hello all, > I want to do non-linear regression by fitting the model (let say, y = > a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must > be in between (0 to 1), and others can be of any values. How can I > perform my job in python? > > Thanks in advance. > > -- Akand http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html From wangcoeus at gmail.com Mon Feb 14 16:46:42 2011 From: wangcoeus at gmail.com (Wang Coeus) Date: Mon, 14 Feb 2011 23:46:42 +0200 Subject: How to create a dict based on such a file? References: Message-ID: Dan Stromberg writes: > On Sun, Feb 13, 2011 at 9:47 PM, Wang Coeus wrote: >> Hi all, >> I am new to python. Currently I encountered a problem, please help me to >> solve this. Thanks in advance! >> I have a file like below: >> ++++++++++++++++++++++++++++++++++++++ >> block1 >> { >> ?key1=value1 >> ?key2=value2 >> ?key3=value3 >> } >> block2 >> { >> ?key1=value4 >> ?key2=value5 >> ?key4=value6 >> } >> ... >> blockn >> { >> ?key1=value7 >> ?key2=value8 >> ?keyn=valuen >> } >> +++++++++++++++++++++++++++++++++++++++ >> Different block may have different keys and even same key in different >> blocks may have different values. >> >> Now I want to get a function, which like this: >> func(key) >> and it will return a dictionary as below: >> func(key1) = [block1:value1,block2:value4,...,blockn:value7] >> and if one block has no "key1" parameter, it will not include in this >> dict. >> >> Thanks a lot! > > pyparsing should be able to make pretty short work of exactly the > format you want. > > FWIW, the creator of the many .ini format(s), Microsoft, no longer > recommends using .ini files. Really Thanks for all your kind help! I will try them. :) -- Coeus In the middle of every difficulty lies opportunity. -- Albert Einstein From sturlamolden at yahoo.no Mon Feb 14 17:28:15 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Mon, 14 Feb 2011 14:28:15 -0800 (PST) Subject: Non-linear regression help in Python References: <963b83e6-ea51-4c36-b212-0deeef657630@o32g2000prb.googlegroups.com> Message-ID: <2b3e0b23-381f-4396-99f7-b7465b472575@x1g2000yqb.googlegroups.com> On 14 Feb, 22:02, Akand Islam wrote: > Hello all, > I want to do non-linear regression by fitting the model (let say, y = > a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must > be in between (0 to 1), and others can be of any values. How can I > perform my job in python? First, install NumPy and SciPy! scipy.optimize.leastsq implements Levenberg-Marquardt, which is close to the 'gold standard' for non-linear least squares. The algorithm will be a bit faster and more accurate if you provide the Jacobian of the residuals, i.e. the partial derivative of r = y - a1*x+b1*x**2+c1*x**3/exp(d1*x**4) with respect to a1, b1, c1, and d1 (stored in a 4 by n matrix). If you have prior information about c1, you have a Bayesian regression problem. You can constrain c1 between 1 and 0 by assuming a beta prior distribution on c1, e.g. c1 ~ Be(z,z) with 1 < z < 2 Then proceed as you would with Bayesian regession -- i.e. EM, Gibbs' sampler, or Metropolis-Hastings. Use scipy.stats.beta to evaluate and numpy.random.beta to sample the beta distribution. The problem is not programming it in Python, but getting the correct equations on paper. Also beware that running the Markov chain Monte Carlo might take a while. Sturla From misnomer at gmail.com Mon Feb 14 17:51:30 2011 From: misnomer at gmail.com (Nicholas Devenish) Date: Mon, 14 Feb 2011 22:51:30 +0000 Subject: How to create a dict based on such a file? In-Reply-To: References: Message-ID: On 14/02/2011 19:25, Dan Stromberg wrote: > pyparsing should be able to make pretty short work of exactly the > format you want. > > FWIW, the creator of the many .ini format(s), Microsoft, no longer > recommends using .ini files. I don't know what Microsoft uses now, but it seemed their immediate successor was the windows registry, which wasn't exactly fun. INI-style files are extremely simple, very easy to parse (if you don't have a handy parsing library for it, which is rare) and very human-readable and modifyable. *If* your configuration data doesn't get more complex than an optionally sectioned flat-file, then it can seem like the right tool for the job. Especially if you need people who aren't exactly programmers to be able to configure and understand the file. As for JSON, another that it seems is often mentioned around such things; I like it, but find it a little verbose for such simple flat configuration files. From steve+comp.lang.python at pearwood.info Mon Feb 14 18:06:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Feb 2011 23:06:58 GMT Subject: How to create a dict based on such a file? References: Message-ID: <4d59b592$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Feb 2011 11:25:00 -0800, Dan Stromberg wrote: > FWIW, the creator of the many .ini format(s), Microsoft, no longer > recommends using .ini files. That's because they want people to use the registry. INI files are simple, easy to parse, lightweight, and human readable and human writable using nothing more than a text editor. For many purposes, they are perfectly fine. As I see it, the biggest problems with INI files are: * the INI file module that comes with Python is quite primitive; * there are many slightly different behaviours you might want in an INI file, and no clean or obvious way to tell which one you are dealing with just from the file. E.g. if you repeat a key twice, does the second line override the first, or add a second value, or is it an error? INI files aren't suitable for everything, but there's no need to avoid them just because Microsoft don't want you using them, or because they're uncool or something... Rant: what I *really hate* is when people use XML just because XML is the in-thing, not because they need it. Instead of: [main] key = value food = spam colour = green you get something like this:
-- Steven From anikom15 at gmail.com Mon Feb 14 18:29:04 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Mon, 14 Feb 2011 15:29:04 -0800 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1297726144.2503.0.camel@localhost.localdomain> On Mon, 2011-02-14 at 11:15 -0800, rantingrick wrote: > On Feb 14, 11:55 am, Michael Sparks wrote: > > It can be broken if someone tries to use the class as is - that is > > treating the class as a model - to drive a display of the ship. If > > it was written using super() then that wouldn't be a problem. > > > > For example, I could write a display mixin that I'd like to use like > > this: > > [snip: miles of code not formatted for 79 chars!] > > That was a nice long winded example of how to break code by using it > in an improper manner. You could have just called the base with one > too many arguments and achieved the same. However the developer would > be suffering from either; severe memory loss and/or lack of reading > comprehension if he tried to use -a- his class interface in a manner > that it was not originally intended. I could likewise use a hammer to > drive screws and then rant and rave later how the hammer is > insufficient. Surely my methods could not be a fault, surely? ;-) That's nowhere near a mile. From rantingrick at gmail.com Mon Feb 14 18:32:18 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 14 Feb 2011 15:32:18 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> On Feb 14, 1:45?pm, Michael Sparks wrote: > I hardly call 87 lines of code "miles of code" though myself. ?I call > it a relatively trivial example aimed at showing the benefit of using > super() in your code rather than hard coding brittle fragility into > your code. You accuse my coding habits of being "brittle" yet you had to go to extraordinarily lengths to break my "fragile" code. Not even considering that my "habit" of hard coding the base is perfectly legal and accepted in Python code. And did you read the link Ian Kelly's provided? In any event, normally i would expect people to use a bit of common sense when wielding an interface ESPECIALLY when they wrote it! Like for instance... If i gave someone a loaded gun i would not bother telling that person "Hey, don't aim the gun at your foot and then pull the trigger because you could blow your pinky toe off"... no, i would expect them to have enough sense not to do such a stupid thing. However, if they *did* happen to blow their pinky toe off i really would not get too upset about it. After all, i've always believed that stupidity should be painful. > No, it was a thought out example of how writing code slightly > differently from how you do now can result in something more > practical, reusable, extendable, and maintainable. Those who write code bases should "design-in" practicality, re- usability, and extendability as a forethought and NOT an afterthought. Of course i am not suggesting that everyone must be clairvoyant. However the vast amount of time involved in a coding project should be spent in the design and testing phases and NOT actually writing code. If you spend more time writing code you are not being professional, you are being sloppy -- and it WILL catch up to you. From prologic at shortcircuit.net.au Mon Feb 14 18:46:24 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 15 Feb 2011 09:46:24 +1000 Subject: Extending classes __init__behavior for newbies In-Reply-To: <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: On Tue, Feb 15, 2011 at 9:32 AM, rantingrick wrote: > In any event, normally i would expect people to use a bit of common > sense when wielding an interface ESPECIALLY when they wrote it! Like > for instance... If i gave someone a loaded gun i would not bother > telling that person "Hey, don't aim the gun at your foot and then pull > the trigger because you could blow your pinky toe off"... no, i would > expect them to have enough sense not to do such a stupid thing. > However, if they *did* happen to blow their pinky toe off i really > would not get too upset about it. After all, i've always believed that > stupidity should be painful. This reminds me of "good engineering practise" where you let the error occur where it lay. Example: >>> def f(a): ... return a + 1 ... >>> f(1) 2 >>> def g(*args): ... if len(args) == 1: ... return args[0] + 1 ... else: ... raise Exception("Invalid arguments") ... >>> g(1) 2 >>> g() Traceback (most recent call last): File "", line 1, in File "", line 5, in g Exception: Invalid arguments >>> g(1, 2) Traceback (most recent call last): File "", line 1, in File "", line 5, in g Exception: Invalid arguments >>> f() Traceback (most recent call last): File "", line 1, in TypeError: f() takes exactly 1 argument (0 given) >>> f(1, 2) Traceback (most recent call last): File "", line 1, in TypeError: f() takes exactly 1 argument (2 given) >>> In that sense, you "trust" that the programmer using your API(s) has read "documentation" and/or "source code" and "understands" how to "correctly" use the API(s). If the programmer doesn't use the API(s) "correctly" f(...) will blow up in his/her face. g(...) will blow up as well but tries to guard against the expected TypeError you would expect if you called f(...) incorrectly. cheers James -- -- James Mills -- -- "Problems are solved by method" From prologic at shortcircuit.net.au Mon Feb 14 18:47:54 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Tue, 15 Feb 2011 09:47:54 +1000 Subject: Extending classes __init__behavior for newbies In-Reply-To: <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: On Tue, Feb 15, 2011 at 9:32 AM, rantingrick wrote: > Those who write code bases should "design-in" practicality, re- > usability, and extendability as a forethought and NOT an afterthought. > Of course i am not suggesting that everyone must be clairvoyant. > However the vast amount of time involved in a coding project should be > spent in the design and testing phases and NOT actually writing code. > If you spend more time writing code you are not being professional, > you are being sloppy -- and it WILL catch up to you. I actually agree with this. :) --JamesMills -- -- James Mills -- -- "Problems are solved by method" From andrea.crotti.0 at gmail.com Mon Feb 14 18:48:18 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Tue, 15 Feb 2011 00:48:18 +0100 Subject: lint warnings Message-ID: <97BBEE48-E686-4A50-A70C-15BEB3307736@gmail.com> I work on emacs with flymake activated and pylint, pyflakes and pep8 running in background to notify for some style problems. Now there are at a couple of pylint warnings which I don't understand 1. Warning (W, filter_enums): Used builtin function 'map' [2 times] what is the problem with using map and other builtin functions? 2. Warning (W): Relative import 'parameters', should be 'othermodule.parameters' if I am in the same directory why should I do a relative import, does it make any difference? I think it's more clear/safe to just import the 'parameters', am I wrong? Thanks, Andrea From aahz at pythoncraft.com Mon Feb 14 18:54:51 2011 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2011 15:54:51 -0800 Subject: Which is the best book to learn python References: <188c0a9f-4e93-4fae-b3f9-e7c84f8030fd@v31g2000pri.googlegroups.com> Message-ID: In article , Jean-Michel Pichavant wrote: > >Python is easy to learn, I'm not sure it's possible to write a bad book >about it. Yes, it is. I can name two: Deitel: Python How to Program Perl to Python Migration -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational science. Most reasoning about it is at best rationalization of gut feelings, and at worst plain wrong." --GvR, python-ideas, 2009-03-01 From wuwei23 at gmail.com Mon Feb 14 19:06:18 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 14 Feb 2011 16:06:18 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: On Feb 15, 9:47?am, James Mills wrote: > On Tue, Feb 15, 2011 at 9:32 AM, rantingrick wrote: > > Those who write code bases should "design-in" practicality, re- > > usability, and extendability as a forethought and NOT an afterthought. > > Of course i am not suggesting that everyone must be clairvoyant. > > However the vast amount of time involved in a coding project should be > > spent in the design and testing phases and NOT actually writing code. > > If you spend more time writing code you are not being professional, > > you are being sloppy -- and it WILL catch up to you. > > I actually agree with this. :) The problem is that it's not a philosophy which the ranting one practices, it's a bludgeon he uses to dump crap on other people for disagreeing with him. The offensive aspect of it is the implication that the rest of us are dumb assholes who don't already know this. From drsalists at gmail.com Mon Feb 14 19:43:50 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 14 Feb 2011 16:43:50 -0800 Subject: How to create a dict based on such a file? In-Reply-To: <4d59b592$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <4d59b592$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Feb 14, 2011 at 3:06 PM, Steven D'Aprano wrote: > On Mon, 14 Feb 2011 11:25:00 -0800, Dan Stromberg wrote: > >> FWIW, the creator of the many .ini format(s), Microsoft, no longer >> recommends using .ini files. > > That's because they want people to use the registry. > > INI files are simple, easy to parse, lightweight, and human readable and > human writable using nothing more than a text editor. For many purposes, > they are perfectly fine. As I see it, the biggest problems with INI files > are: > > * the INI file module that comes with Python is quite primitive; > > * there are many slightly different behaviours you might want in an INI > file, and no clean or obvious way to tell which one you are dealing with > just from the file. More to the point, there are many dialects of ini files, and nothing more than a defacto standard for how they should work. They also stand out like a sore thumb on anything but Windows, and look a bit anachronistic on Windows. But I don't hate ini files - I just think they aren't that clearly a great choice. If you want to use them, fine. If you recommend them, fine. From rantingrick at gmail.com Mon Feb 14 19:53:16 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 14 Feb 2011 16:53:16 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: On Feb 14, 6:06?pm, alex23 wrote: > On Feb 15, 9:47?am, James Mills wrote: > > > On Tue, Feb 15, 2011 at 9:32 AM, rantingrick wrote: ... [snip: eloquent speech!] ... > > I actually agree with this. :) > The problem is that it's not a philosophy which the ranting one > practices, Actually I could argue quite *successfully* that i have been designing the rebirth (and fostering the forward thinking evolution!) of the entire Python community and some very important aspects of the language for the last couple of years. I have risen through the ranks from a mere scribe to a truly Pythonic visionary. However, some of my fellow "engineers" refuse to move from the design phase into the production phase due to "silly squabbling" and "petty posturing". We can do many great things if we can put our egos aside and join together in a common goal. [Anecdote] I always find it interesting how once a person joins an online group as a "helper" they cannot ask questions anymore. It's like an unwritten law you dare not break because if you do your "peers" will see you as weak and they will pounce on you, discredit you, and then excommunicate you! Any sign of weakness and your out. However if you show force and brow beat those who dare challenge you then fear will elevate you through the ranks. This should not be the case. No one person knows everything. Not even the great Guido van Rossum himself could have engineered something like Python alone. Sure, Python is *his* brainchild (and a very beautiful one!) however, he would have made many mistakes and/or left out many good designs if he did not have the help of a strong community. [Back on track] I would like to see this group drop the egos and start really working together. Stop being afraid of how you appear to others and be yourself. Some folks will be good in one area and other folks in another. Only together can we conquer all problem domains. In the end i promise they will respect you more for your honesty. And it will not be a respect forged from fear, no, it will be something greater! A respect forged from collaboration. A respect of comrades in arms. This is the future i bring to c.l.py! From clp2 at rebertia.com Mon Feb 14 21:07:41 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 14 Feb 2011 18:07:41 -0800 Subject: lint warnings In-Reply-To: <97BBEE48-E686-4A50-A70C-15BEB3307736@gmail.com> References: <97BBEE48-E686-4A50-A70C-15BEB3307736@gmail.com> Message-ID: On Mon, Feb 14, 2011 at 3:48 PM, Andrea Crotti wrote: > I work on emacs with flymake activated and pylint, pyflakes and pep8 running in background to notify for some style problems. > > Now there are at a couple of pylint warnings which I don't understand > 1. Warning (W, filter_enums): Used builtin function 'map' [2 times] > what is the problem with using map and other builtin functions? See archived thread on the same subject: "pylint: What's wrong with the builtin map()" http://mail.python.org/pipermail/python-list/2006-October/461535.html Cheers, Chris From ben+python at benfinney.id.au Mon Feb 14 22:10:38 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 15 Feb 2011 14:10:38 +1100 Subject: lint warnings References: Message-ID: <87vd0mgfgx.fsf@benfinney.id.au> Andrea Crotti writes: > I work on emacs with flymake activated and pylint, pyflakes and pep8 > running in background to notify for some style problems. > > Now there are at a couple of pylint warnings which I don't understand > 1. Warning (W, filter_enums): Used builtin function 'map' [2 times] > what is the problem with using map and other builtin functions? The ?map? builtin is deprecated; using a list comprehension is neater and more efficient. > 2. Warning (W): Relative import 'parameters', should be 'othermodule.parameters' > if I am in the same directory why should I do a relative import, does > it make any difference? It makes the code unnecessarily ambiguous; the person reading the code can't tell that it's a relative import. > I think it's more clear/safe to just import the 'parameters', am I > wrong? You can use the explicit relative import syntax (I don't know if that satisfies ?pylint?). -- \ ?I wish there was a knob on the TV to turn up the intelligence. | `\ There's a knob called ?brightness? but it doesn't work.? | _o__) ?Eugene P. Gallagher | Ben Finney From anikom15 at gmail.com Mon Feb 14 22:17:41 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Mon, 14 Feb 2011 19:17:41 -0800 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: <1297739861.7382.0.camel@localhost.localdomain> On Mon, 2011-02-14 at 16:53 -0800, rantingrick wrote: > On Feb 14, 6:06 pm, alex23 wrote: > > On Feb 15, 9:47 am, James Mills wrote: > > > > > On Tue, Feb 15, 2011 at 9:32 AM, rantingrick wrote: > ... > [snip: eloquent speech!] > ... > > > I actually agree with this. :) > > The problem is that it's not a philosophy which the ranting one > > practices, > > Actually I could argue quite *successfully* that i have been designing > the rebirth (and fostering the forward thinking evolution!) of the > entire Python community and some very important aspects of the > language for the last couple of years. I have risen through the ranks > from a mere scribe to a truly Pythonic visionary. However, some of my > fellow "engineers" refuse to move from the design phase into the > production phase due to "silly squabbling" and "petty posturing". We > can do many great things if we can put our egos aside and join > together in a common goal. > > [Anecdote] > I always find it interesting how once a person joins an online group > as a "helper" they cannot ask questions anymore. It's like an > unwritten law you dare not break because if you do your "peers" will > see you as weak and they will pounce on you, discredit you, and then > excommunicate you! Any sign of weakness and your out. However if you > show force and brow beat those who dare challenge you then fear will > elevate you through the ranks. This should not be the case. No one > person knows everything. Not even the great Guido van Rossum himself > could have engineered something like Python alone. Sure, Python is > *his* brainchild (and a very beautiful one!) however, he would have > made many mistakes and/or left out many good designs if he did not > have the help of a strong community. > > [Back on track] > I would like to see this group drop the egos and start really working > together. Stop being afraid of how you appear to others and be > yourself. Some folks will be good in one area and other folks in > another. Only together can we conquer all problem domains. > > In the end i promise they will respect you more for your honesty. And > it will not be a respect forged from fear, no, it will be something > greater! A respect forged from collaboration. A respect of comrades in > arms. This is the future i bring to c.l.py! HEIL DER FUHRER! From wuwei23 at gmail.com Mon Feb 14 22:36:57 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 14 Feb 2011 19:36:57 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: <8595acb6-79e6-4720-8773-b3ee254e8a4d@u24g2000prn.googlegroups.com> rantingrick wrote: > A respect forged from collaboration. A respect of comrades in > arms. This is the future i bring to c.l.py! Really? I see no collaboration, respect nor camaraderie in anything you've posted to date. So I'm confident the future you bring will be pretty much the same as the past: arrogance, empty rhetoric and endless trolling. BTW, do you see the contradiction in the following two statements? > We can do many great things if we can put our egos aside and join > together in a common goal. > I have risen through the ranks > from a mere scribe to a truly Pythonic visionary. How's that ego-aside process working out for you? One last time: no one will respect you until you act in a manner that warrants it. Huge textual screeds aren't anything to be proud of; I have written markov chainers that produce more convincing rants than you. The _only_ thing that matters here is the code you produce. From wuwei23 at gmail.com Mon Feb 14 22:41:00 2011 From: wuwei23 at gmail.com (alex23) Date: Mon, 14 Feb 2011 19:41:00 -0800 (PST) Subject: How to create a dict based on such a file? References: <4d59b592$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <090e5cf2-c15c-41e5-a4e5-b028105417c3@m27g2000prj.googlegroups.com> On Feb 15, 9:06?am, Steven D'Aprano wrote: > As I see it, the biggest problems with INI files are: > > * the INI file module that comes with Python is quite primitive; > > * there are many slightly different behaviours you might want in an INI > file, and no clean or obvious way to tell which one you are dealing with > just from the file. [...] > Rant: what I *really hate* is when people use XML just because XML is the > in-thing, not because they need it. Could it possibly be then that people use XML because a) the support is better and b) the behaviour is more predictable? That sounds more like good tool choice than faddism. From steve+comp.lang.python at pearwood.info Mon Feb 14 22:44:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Feb 2011 03:44:07 GMT Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: <4d59f687$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 09:47:54 +1000, James Mills wrote: > On Tue, Feb 15, 2011 at 9:32 AM, rantingrick > wrote: >> Those who write code bases should "design-in" practicality, re- >> usability, and extendability as a forethought and NOT an afterthought. >> Of course i am not suggesting that everyone must be clairvoyant. >> However the vast amount of time involved in a coding project should be >> spent in the design and testing phases and NOT actually writing code. >> If you spend more time writing code you are not being professional, you >> are being sloppy -- and it WILL catch up to you. > > I actually agree with this. :) I don't. If you (generic you) have separate "write the code" and "test the code" phases, your project is in trouble. You can probably get away with it if it's a tiny throw-away script, but for anything more substantial, you should be testing *as you are writing*. The two need to go in parallel. I don't follow full-blown test driven development where you write the test before you write the code, but still, the time to find out your infrastructure is fundamentally broken is *before* you have finished it, not three months later when you have built the entire app on top of it. -- Steven From hayesjdno3 at yahoo.com Mon Feb 14 22:55:47 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Mon, 14 Feb 2011 19:55:47 -0800 (PST) Subject: files,folders,paths References: <169147.32700.qm@web33407.mail.mud.yahoo.com> <2c3c533d-5c7a-4c4e-8f52-25ae80fcf761@o8g2000vbq.googlegroups.com> Message-ID: well i think i will close this out. redid recursive foldering now for 3rd or 4th time. below script works from a windows to another folder (destination1) or a unc path(destination2). i tried it on my linux box, and the error deals with writing to a remote smb share. i think if it was mounted somewhere, it would work fine with something like dest1, but changing the path(or mounting the remote drive to backup2 for the lazy ). #!/usr/bin/python import wx,os,string,fnmatch,shutil,tempfile,time,getpass from datetime import * from os.path import join, getsize def weekChoice(): #week = 0 dateNum = datetime.now().day if dateNum <=7: week = 1 elif (dateNum >= 8) and (dateNum <= 14): week = 2 elif (dateNum >= 15) and (dateNum <= 21): week = 3 elif dateNum > 22: week = 4 else: print "error!!!!" return week def getusername(): username = getpass.getuser() return username def homeDir(): homedir = os.path.expanduser('~') try: from win32com.shell import shellcon, shell homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) except ImportError: homedir = os.path.expanduser("~") return homedir def source1(): week = weekChoice() homedir = homeDir() #changed backupdir to source source = os.path.join(homedir, "backup") return source def destination1(): week = weekChoice() homedir = homeDir() remotedir = os.path.join(homedir, "backup2") weekstr = "week"+str(week) destination = os.path.join(remotedir, weekstr) return destination def destination2(): username = getusername() week = weekChoice() weekstr = "week"+str(week) destination = os.path.join("//Mothera",username,weekstr) #need to mount the smb share somewhere return destination def backupall(): week = weekChoice() weekstr = "week"+str(week) source = source1() destination = destination2() # change this around to suit needs for (path, dirs, files) in os.walk(source): for fname in dirs: leftover = path.replace(source, '') #print "leftover = ",leftover currentdir = destination+leftover #print "currentdir = ",currentdir try: #print "dest folder to make",os.path.join(currentdir,fname) os.mkdir(os.path.join(currentdir,fname),0755) except: print "error folder" for fname in files: leftover = path.replace(source, '') #print "leftover = ",leftover currentdir = destination+leftover #print "currentdir = ",currentdir try: #print "dest file to make",os.path.join(currentdir,fname) shutil.copy2(os.path.join(path,fname),os.path.join(currentdir,fname)) except: print "error file" backupall() From steve+comp.lang.python at pearwood.info Mon Feb 14 22:58:07 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Feb 2011 03:58:07 GMT Subject: lint warnings References: <87vd0mgfgx.fsf@benfinney.id.au> Message-ID: <4d59f9ce$0$29993$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 14:10:38 +1100, Ben Finney wrote: > Andrea Crotti writes: > >> I work on emacs with flymake activated and pylint, pyflakes and pep8 >> running in background to notify for some style problems. >> >> Now there are at a couple of pylint warnings which I don't understand >> 1. Warning (W, filter_enums): Used builtin function 'map' [2 times] >> what is the problem with using map and other builtin functions? > > The ?map? builtin is deprecated; I don't believe it is. Do you have any evidence for this claim? > using a list comprehension is neater and more efficient. The first is a matter of opinion, the second is demonstrably untrue. Testing in Python 3.1, there is no significant difference when the function is a pure Python function, although map is slightly faster: >>> from timeit import Timer >>> t1 = Timer('[f(x) for x in range(1000)]', 'def f(x): return x+1') >>> t2 = Timer('list(map(f, range(1000)))', 'def f(x): return x+1') >>> t1.timeit(number=100) 0.09910106658935547 >>> t2.timeit(number=100) 0.08968997001647949 >>> t1.timeit(number=1000) 0.9915580749511719 >>> t2.timeit(number=1000) 0.9404010772705078 If the function is a built-in written in C, map can be significantly faster: >>> t1 = Timer('[len(s) for s in "a"*1000]', '') >>> t2 = Timer('list(map(len, "a"*1000))', '') >>> t1.timeit(number=100) 0.0598909854888916 >>> t2.timeit(number=100) 0.02748703956604004 >>> t1.timeit(number=10000) 3.6018471717834473 >>> t2.timeit(number=10000) 1.8807408809661865 The only time list comps are faster is if you have a expression which can be executed in-line in the comprehension, but needs to be written as a Python function in map. And even then, the difference is just a multiplicative constant, not a Big Oh difference. -- Steven From wallenpb at gmail.com Mon Feb 14 23:12:38 2011 From: wallenpb at gmail.com (Bill Allen) Date: Mon, 14 Feb 2011 22:12:38 -0600 Subject: Which is the best book to learn python In-Reply-To: <188c0a9f-4e93-4fae-b3f9-e7c84f8030fd@v31g2000pri.googlegroups.com> References: <188c0a9f-4e93-4fae-b3f9-e7c84f8030fd@v31g2000pri.googlegroups.com> Message-ID: Alan Gauld has written a very good online book called Learning to Program. I would definitely recommend it. http://www.alan-g.me.uk/l2p/index.htm -Bill On Mon, Jan 24, 2011 at 11:09, santosh hs wrote: > Hi All, > i am beginner to python please tell me which is the best available > reference for beginner to start from novice > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sohel807 at gmail.com Mon Feb 14 23:21:40 2011 From: sohel807 at gmail.com (Akand Islam) Date: Mon, 14 Feb 2011 20:21:40 -0800 (PST) Subject: Non-linear regression help in Python References: <963b83e6-ea51-4c36-b212-0deeef657630@o32g2000prb.googlegroups.com> Message-ID: <48858661-a273-4b17-b3f2-a13ede1486b0@g11g2000vbq.googlegroups.com> On Feb 14, 3:24?pm, Krzysztof Bieniasz wrote: > Dnia Mon, 14 Feb 2011 13:02:25 -0800, Akand Islam napisa?(a): > > > Hello all, > > I want to do non-linear regression by fitting the model (let say, y = > > a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must > > be in between (0 to 1), and others can be of any values. How can I > > perform my job in python? > > > Thanks in advance. > > > -- Akand > > http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html Dear Krzysztof Bieniasz, Thanks for reply. -- Akand From sohel807 at gmail.com Mon Feb 14 23:24:17 2011 From: sohel807 at gmail.com (Akand Islam) Date: Mon, 14 Feb 2011 20:24:17 -0800 (PST) Subject: Non-linear regression help in Python References: <963b83e6-ea51-4c36-b212-0deeef657630@o32g2000prb.googlegroups.com> <2b3e0b23-381f-4396-99f7-b7465b472575@x1g2000yqb.googlegroups.com> Message-ID: <54ebfd6f-b626-457b-bcc3-ef0b3f591dc8@k16g2000vbq.googlegroups.com> On Feb 14, 4:28?pm, sturlamolden wrote: > On 14 Feb, 22:02, Akand Islam wrote: > > > Hello all, > > I want to do non-linear regression by fitting the model (let say, y = > > a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must > > be in between (0 to 1), and others can be of any values. How can I > > perform my job in python? > > First, install NumPy and SciPy! > > scipy.optimize.leastsq implements Levenberg-Marquardt, which is close > to the 'gold standard' for non-linear least squares. The algorithm > will be a bit faster and more accurate if you provide the Jacobian of > the residuals, i.e. the partial derivative of > > ? ?r = y - a1*x+b1*x**2+c1*x**3/exp(d1*x**4) > > with respect to a1, b1, c1, and d1 (stored in a 4 by n matrix). > > If you have prior information about c1, you have a Bayesian regression > problem. You can constrain c1 between 1 and 0 by assuming a beta prior > distribution on c1, e.g. > > ? ?c1 ~ Be(z,z) with 1 < z < 2 > > Then proceed as you would with Bayesian regession -- i.e. EM, Gibbs' > sampler, or Metropolis-Hastings. Use scipy.stats.beta to evaluate and > numpy.random.beta to sample the beta distribution. The problem is not > programming it in Python, but getting the correct equations on paper. > Also beware that running the Markov chain Monte Carlo might take a > while. > > Sturla Dear Sturlamolden, Thanks for reply. I will follow-up if I need further assistance. -- Akand From anikom15 at gmail.com Mon Feb 14 23:31:14 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Mon, 14 Feb 2011 20:31:14 -0800 Subject: How to create a dict based on such a file? In-Reply-To: <090e5cf2-c15c-41e5-a4e5-b028105417c3@m27g2000prj.googlegroups.com> References: <4d59b592$0$29967$c3e8da3$5496439d@news.astraweb.com> <090e5cf2-c15c-41e5-a4e5-b028105417c3@m27g2000prj.googlegroups.com> Message-ID: <1297744274.9304.0.camel@localhost.localdomain> On Mon, 2011-02-14 at 19:41 -0800, alex23 wrote: > On Feb 15, 9:06 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > > As I see it, the biggest problems with INI files are: > > > > * the INI file module that comes with Python is quite primitive; > > > > * there are many slightly different behaviours you might want in an INI > > file, and no clean or obvious way to tell which one you are dealing with > > just from the file. > > [...] > > > Rant: what I *really hate* is when people use XML just because XML is the > > in-thing, not because they need it. > > Could it possibly be then that people use XML because a) the support > is better and b) the behaviour is more predictable? That sounds more > like good tool choice than faddism. But why is the support better? ... faddism. From drsalists at gmail.com Tue Feb 15 00:09:02 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 14 Feb 2011 21:09:02 -0800 Subject: How to create a dict based on such a file? In-Reply-To: <1297744274.9304.0.camel@localhost.localdomain> References: <4d59b592$0$29967$c3e8da3$5496439d@news.astraweb.com> <090e5cf2-c15c-41e5-a4e5-b028105417c3@m27g2000prj.googlegroups.com> <1297744274.9304.0.camel@localhost.localdomain> Message-ID: On Mon, Feb 14, 2011 at 8:31 PM, Westley Mart?nez wrote: > On Mon, 2011-02-14 at 19:41 -0800, alex23 wrote: >> On Feb 15, 9:06 am, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: >> > As I see it, the biggest problems with INI files are: >> > >> > * the INI file module that comes with Python is quite primitive; >> > >> > * there are many slightly different behaviours you might want in an INI >> > file, and no clean or obvious way to tell which one you are dealing with >> > just from the file. >> >> [...] >> >> > Rant: what I *really hate* is when people use XML just because XML is the >> > in-thing, not because they need it. >> >> Could it possibly be then that people use XML because a) the support >> is better and b) the behaviour is more predictable? That sounds more >> like good tool choice than faddism. > But why is the support better? ... faddism. Well...: 1) XML was one of the first such interchange formats, so it naturally got some press; it was an idea whose time had come. It's widely accepted that sometimes a first mover gains an advantage over follow-on products, even if it's only temporary. 2) XML is highly general 3) XML doesn't suffer from the weird exceptions to general rules that something like YAML has But in the future, I'll likely lean more on JSON. From steve+comp.lang.python at pearwood.info Tue Feb 15 00:36:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Feb 2011 05:36:02 GMT Subject: How to create a dict based on such a file? References: <4d59b592$0$29967$c3e8da3$5496439d@news.astraweb.com> <090e5cf2-c15c-41e5-a4e5-b028105417c3@m27g2000prj.googlegroups.com> Message-ID: <4d5a10c2$0$29993$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Feb 2011 19:41:00 -0800, alex23 wrote: > On Feb 15, 9:06?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> As I see it, the biggest problems with INI files are: >> >> * the INI file module that comes with Python is quite primitive; >> >> * there are many slightly different behaviours you might want in an INI >> file, and no clean or obvious way to tell which one you are dealing >> with just from the file. > > [...] > >> Rant: what I *really hate* is when people use XML just because XML is >> the in-thing, not because they need it. > > Could it possibly be then that people use XML because a) the support is > better and b) the behaviour is more predictable? That sounds more like > good tool choice than faddism. Of course it *could* be, but is it? I'm certainly not denying that XML can be useful for many applications, nor am I saying that INI files are sufficient for everything. But if all you need is: key = value then why use this? What benefit does it give? It just increases the number of things that can go wrong. -- Steven From ben+python at benfinney.id.au Tue Feb 15 00:45:15 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 15 Feb 2011 16:45:15 +1100 Subject: lint warnings References: <87vd0mgfgx.fsf@benfinney.id.au> <4d59f9ce$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mxlxhmvo.fsf@benfinney.id.au> Steven D'Aprano writes: > On Tue, 15 Feb 2011 14:10:38 +1100, Ben Finney wrote: > > The ?map? builtin is deprecated; > > I don't believe it is. Do you have any evidence for this claim? I was mis-remembering PEP 3100. Anyway, I regard it as deprecated; list comprehensions are more flexible and cleaner. I agree with the ?pylint? warning to that effect. -- \ ?Corporation, n. An ingenious device for obtaining individual | `\ profit without individual responsibility.? ?Ambrose Bierce, | _o__) _The Devil's Dictionary_, 1906 | Ben Finney From steve+comp.lang.python at pearwood.info Tue Feb 15 02:06:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Feb 2011 07:06:35 GMT Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d5a25fb$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Feb 2011 23:42:06 +0000, Rhodri James wrote: > On Fri, 11 Feb 2011 02:08:01 -0000, Steven D'Aprano > wrote: > >> On Thu, 10 Feb 2011 15:48:47 +0000, Cousin Stanley wrote: >> >>> Steven D'Aprano wrote: >>> >>>> I have a tkinter application under Python 2.6 which is shows text in >>>> a giant font, about twenty(?) times larger than expected. [...] > In this case I think you're missing a hyphen. Try > > titlefont = '-Adobe-Helvetica-Bold-R-Normal--*-180-*' Thanks for the suggestion, but xlsfonts returns the same eight font files regardless of whether the hyphen is there or not. (I wouldn't expect otherwise, since the font matching treats * as a text wildcard and will let it cross field boundaries.) -- Steven From duncan.booth at invalid.invalid Tue Feb 15 03:36:52 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Feb 2011 08:36:52 GMT Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: Westley Mart?nez wrote: >> In the end i promise they will respect you more for your honesty. And >> it will not be a respect forged from fear, no, it will be something >> greater! A respect forged from collaboration. A respect of comrades in >> arms. This is the future i bring to c.l.py! > HEIL DER FUHRER! Godwin was right. You lose. -- Duncan Booth http://kupuguy.blogspot.com From andrea.crotti.0 at gmail.com Tue Feb 15 04:21:08 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Tue, 15 Feb 2011 10:21:08 +0100 Subject: lint warnings In-Reply-To: <87vd0mgfgx.fsf@benfinney.id.au> References: <87vd0mgfgx.fsf@benfinney.id.au> Message-ID: Il giorno 15/feb/2011, alle ore 04.10, Ben Finney ha scritto: > Andrea Crotti writes: > The ?map? builtin is deprecated; using a list comprehension is neater > and more efficient. Ok well it depends, map(int, biglist) is better than: [int(x) for x in biglist] at least for me. Efficiency is probably not a big issue apparently, and it's really not important until I see that this is a bottleneck. > > It makes the code unnecessarily ambiguous; the person reading the code > can't tell that it's a relative import. Yes but what if I move those two files (parameter and the importing module) away, the import will continue to work if it's not relative to the upper directory. From alain.spineux at gmail.com Tue Feb 15 04:45:29 2011 From: alain.spineux at gmail.com (alain.spineux) Date: Tue, 15 Feb 2011 01:45:29 -0800 (PST) Subject: generating .zip including __main__.py file in top root using distutils References: <4d634b43-8438-4eed-8c69-38fdb268e520@z20g2000yqe.googlegroups.com> Message-ID: <43feb5c0-03c7-4fac-b381-8272e4503bf7@o20g2000yqk.googlegroups.com> I answer myself to put my question on top of the list again. On Feb 12, 7:47?pm, aspineux wrote: > Python 2.6 can run a zip file, searching for __main__.py in the root > of the zip archive and running it. > How can I create such an archive using distutils (and not > setuptools) ? > > If I use > # python setup.py bdist --format=zip > I get a "dumb" zip file with a deep tree structure from "/" and I > cannot put the __main__.py in the root archive > > If I use > # python setup.py sdist --format=zip > I get a more compact tree. But the tree start bellow directory named > "mypackage-version", > > my-package-1.0/ > ? setup.py > ? __main__.py > ? ........ > > If I use setuptool, generating .EGG I get exacly what I want ! > But I read it is bad to use setuptool and EGGs since pip is > available :-) > > I was hopping distutils have been updated when adding the zip trick, > but I didn't find the trick. > > Help From andrea.crotti.0 at gmail.com Tue Feb 15 04:53:56 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Tue, 15 Feb 2011 10:53:56 +0100 Subject: interleave string Message-ID: <1CB62665-3B50-4A06-89D9-457B547C8A65@gmail.com> Just a curiosity not a real problem, I want to pass from a string like xxaabbddee to xx:aa:bb:dd:ee so every two characters insert a ":". At the moment I have this ugly inliner interleaved = ':'.join(orig[x:x+2] for x in range(0, len(orig), 2)) but also something like this would work [''.join((x,y)) for x, y in zip(orig[0::2], orig[1::2])] any other ideas? From wojciech_mula at poczta.null.onet.pl.invalid Tue Feb 15 05:09:14 2011 From: wojciech_mula at poczta.null.onet.pl.invalid (Wojciech =?ISO-8859-2?Q?Mu=B3a?=) Date: Tue, 15 Feb 2011 11:09:14 +0100 Subject: interleave string References: Message-ID: <20110215110914.0926251a@cat.tac> On Tue, 15 Feb 2011 10:53:56 +0100 Andrea Crotti wrote: > Just a curiosity not a real problem, I want to pass from a string like > > xxaabbddee > to > xx:aa:bb:dd:ee > > so every two characters insert a ":". > At the moment I have this ugly inliner > interleaved = ':'.join(orig[x:x+2] for x in range(0, > len(orig), 2)) > > but also something like this would work > [''.join((x,y)) for x, y in zip(orig[0::2], orig[1::2])] > > any other ideas? import re s = 'xxaabbddee' m = re.compile("(..)") s1 = m.sub("\\1:", s)[:-1] w. From valentin at syntactic.org Tue Feb 15 05:19:15 2011 From: valentin at syntactic.org (Valentin Baciu) Date: Tue, 15 Feb 2011 12:19:15 +0200 Subject: interleave string In-Reply-To: <1CB62665-3B50-4A06-89D9-457B547C8A65@gmail.com> References: <1CB62665-3B50-4A06-89D9-457B547C8A65@gmail.com> Message-ID: Hello, How about this: >>> str = 'xxaabbddee' >>> ':'.join(map(''.join, zip(str[::2], str[1::2]))) In my example, it should not matter that the letters are repeating. On Tue, Feb 15, 2011 at 11:53 AM, Andrea Crotti wrote: > Just a curiosity not a real problem, I want to pass from a string like > > xxaabbddee > to > xx:aa:bb:dd:ee > > so every two characters insert a ":". > At the moment I have this ugly inliner > interleaved = ':'.join(orig[x:x+2] for x in range(0, len(orig), 2)) > > but also something like this would work > [''.join((x,y)) for x, y in zip(orig[0::2], orig[1::2])] > > any other ideas? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pcdinh at gmail.com Tue Feb 15 05:57:09 2011 From: pcdinh at gmail.com (Dinh) Date: Tue, 15 Feb 2011 17:57:09 +0700 Subject: Missing SIGCHLD Message-ID: Hi, I currently build a process management system which is able to fork child processes (fork()) and keep them alive (waitpid() ). if pid in self.current_workers: os.waitpid(pid, 0) If a child process dies, it should trigger a SIGCHLD signal and a handler is installed to catch the signal and start a new child process. The code is nothing special, just can be seen in any Python tutorial you can find on the net. signal.signal(signal.SIGCHLD, self.restart_child_process) signal.signal(signal.SIGHUP, self.handle) # reload signal.signal(signal.SIGINT, self.handle) signal.signal(signal.SIGTERM, self.handle) signal.signal(signal.SIGQUIT, self.handle) However, this code does not always work as expected. Most of the time, it works. When a child process exits, the master process receives a SIGCHLD and restart_child_process() method is invoked automatically to start a new child process. But the problem is that sometimes, I know a child process exits due to an unexpected exception (via log file) but it seems that master process does not know about it. No SIGCHLD and so restart_child_process() is not triggered. Therefore, no new child process is forked. Could you please kindly tell me why this happens? Is there any special code that need being installed to ensure that every dead child will be informed correctly? Mac OSX 10.6 Python 2.6.6 Thanks Dinh -------------- next part -------------- An HTML attachment was scrubbed... URL: From aspineux at gmail.com Tue Feb 15 06:18:05 2011 From: aspineux at gmail.com (aspineux) Date: Tue, 15 Feb 2011 03:18:05 -0800 (PST) Subject: Question on Creating exe file with py2exe References: <494b6577-09ea-45c7-8b22-5f5d10061a78@x4g2000prf.googlegroups.com> <7549e107-d7c0-488e-b164-fe6cf11cb498@n1g2000yqm.googlegroups.com> <236bea12-00ef-4e30-b8df-ff33998874bd@o21g2000prn.googlegroups.com> Message-ID: <5a30c17d-a70d-4bfe-ae91-2fca7b907e5a@x1g2000yqb.googlegroups.com> On 13 f?v, 06:20, joy99 wrote: > On Feb 13, 1:29?am, aspineux wrote: > > > > > > > Hi > > > I'm releasing a .exe made with py2exe myself an got this problem too. > > 99% of the time the required DLL is already installed by another > > application and you don't need to care about it. > > The 1% is about empty or fresh windows install (server most of the > > time) > > For them, I provide a link to the M$ vcredist and a warning in my > > download page asking them to install it them self. > > > Take a look at my site for the vcredist link :http://www.magikmon.com/mksbackup/download.en.html > > > Regards > > > Alain > > > On Feb 12, 9:06?pm, joy99 wrote: > > > > Dear Room, > > > > I am using Windows XP (SP2) and a Python Version "Python 2.6.5 > > > (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on > > > win32". > > > > I was looking to create exe files. Reviewing various posts here, I > > > felt py2exe may be the best thing I can opt for. > > > > But for Python2.6 I found the following note in the py2exe tutorial: > > > "For Python 2.6, the DLL you need is called MSVCR90.dll. Py2exe is not > > > able to automatically include this DLL in your dist directory, so you > > > must provide it yourself. > > > > To complicate things, there is more than one version of this DLL in > > > existance, each with the same filename. You need the same version that > > > the Python interpreter was compiled with, which is version > > > 9.0.21022.8. Through the remainder of these instructions, hover your > > > mouse over the dll file (or the vcredist_x86.exe installer executable) > > > to confirm which version you've got. " > > > > My questions are: > > > (i) From where I can download "MSVCR90.dll" ? Is there any trusted > > > site? > > > (ii) How to install the same? > > > (iii) Would py2exe work fine if I install it? > > > (iv) Is there any other exe creating program which does not have all > > > these problems? > > > > As it is a room for expert python developers, I felt to ask you, if > > > any one can kindly find some time to resolve my query, I would be > > > honored. > > > > Thanks in Advance, > > > Best Regards, > > > Subhabrata. > > Hi Alain, > Thank you for your product information. But, with my problem > installation is okay. > The first two steps: > "from distutils.core import setup > ?import py2exe" > but as I am giving > "setup(console=['file.py'])" > > the setup file is not being generated. What do you mean ? Do you expect the 3 lines above will generate a setup.py file ? You are wrong you must create your setup.py file yourself, and this file must contains the 3 lines above, and more a lot more .. Then you will run python setup.py py2exe to generate your .exe file > It is giving some error > messages. > Any suggestions? > Best Regards, > Subhabrata.- Masquer le texte des messages pr?c?dents - > > - Afficher le texte des messages pr?c?dents - From michels at mps.mpg.de Tue Feb 15 07:00:35 2011 From: michels at mps.mpg.de (Helmut Michels) Date: Tue, 15 Feb 2011 13:00:35 +0100 Subject: [ANN] Data Plotting Library DISLIN 10.1 Message-ID: Dear Python users, I am pleased to announce version 10.1 of the data plotting software DISLIN. DISLIN is a high-level and easy to use plotting library for displaying data as curves, bar graphs, pie charts, 3D-colour plots, surfaces, contours and maps. Several output formats are supported such as X11, VGA, PostScript, PDF, CGM, WMF, HPGL, TIFF, GIF, PNG, BMP and SVG. The software is available for the most C, Fortran 77 and Fortran 90/95 compilers. Plotting extensions for the interpreting languages Perl, Python and Java are also supported. DISLIN distributions can be copied from the DISLIN home page http://www.dislin.de and via FTP from the server ftp://ftp.gwdg.de/pub/grafik/dislin All DISLIN distributions are free for non-commercial use. Licenses for commercial use are available from the site http://www.dislin.de. ------------------- Helmut Michels Max Planck Institute for Solar System Research Phone: +49 5556 979-334 Max-Planck-Str. 2 Fax : +49 5556 979-240 D-37191 Katlenburg-Lindau Mail : michels at mps.mpg.de From alex at moreati.org.uk Tue Feb 15 08:21:12 2011 From: alex at moreati.org.uk (Alex Willmer) Date: Tue, 15 Feb 2011 05:21:12 -0800 (PST) Subject: interleave string References: <20110215110914.0926251a@cat.tac> Message-ID: <23f12181-e255-4079-8ec0-29f196a0fcc2@q36g2000yqn.googlegroups.com> On Feb 15, 10:09?am, Wojciech Mu?a wrote: > import re > > s = 'xxaabbddee' > m = re.compile("(..)") > s1 = m.sub("\\1:", s)[:-1] One can modify this slightly: s = 'xxaabbddee' m = re.compile('..') s1 = ':'.join(m.findall(s)) Depending on one's taste this could be clearer. The more general answer, from the itertools docs: from itertools import izip_longest def grouper(n, iterable, fillvalue=None): "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" args = [iter(iterable)] * n return izip_longest(fillvalue=fillvalue, *args) s2 = ':'.join(''.join(pair) for pair in grouper(2, s, '')) Note that this behaves differently to the previous solutions, for sequences with an odd length. From gerald.britton at gmail.com Tue Feb 15 09:03:45 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 15 Feb 2011 09:03:45 -0500 Subject: lint warnings Message-ID: I find: map(func, iterable) to be "neater" than: [func(item) for item in iterable] If nothing else, the "map" version is shorter. More importantly, in the 2.x series (which I am often limited to for compatibility reasons), the variable used in the list comprehension leaks to the following code: $ python Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> del item Traceback (most recent call last): File "", line 1, in NameError: name 'item' is not defined >>> [int(item) for item in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> item 9 >>> which can cause hard-to-find bugs. Fortunately this has been corrected in 3.x. Also, as already shown, the map version is faster. BTW, if you like: [item for item in iterable if predicate(item)] you can use: filter(predicate, item) I find the latter neater for the same reasons as above -- Gerald Britton From duncan.booth at invalid.invalid Tue Feb 15 09:32:13 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Feb 2011 14:32:13 GMT Subject: lint warnings References: Message-ID: Gerald Britton wrote: > I find: > > map(func, iterable) > > to be "neater" than: > > [func(item) for item in iterable] > > If nothing else, the "map" version is shorter. That's only true if you wanted to call an existing function. If you wanted to do something involving a more complex expression that you can write inline then the list comprehension is shorter. > Also, as already shown, the map version is faster. In most cases the list comprehension is faster. Try timing it. C:\Python27>python.exe lib\timeit.py -s "def double(x): return x*2" -s "data=range(10000)" "map(double, data)" 1000 loops, best of 3: 1.82 msec per loop C:\Python27>python.exe lib\timeit.py -s "def double(x): return x*2" -s "data=range(10000)" "[x*2 for x in data]" 1000 loops, best of 3: 879 usec per loop map is only likely to be faster if you wanted to call a function in both cases. If you have an expression that can be inlined you save the function call overhead with the list comprehension. -- Duncan Booth http://kupuguy.blogspot.com From anikom15 at gmail.com Tue Feb 15 09:42:27 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Tue, 15 Feb 2011 06:42:27 -0800 Subject: Extending classes __init__behavior for newbies In-Reply-To: References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> Message-ID: <1297780947.12352.2.camel@localhost.localdomain> On Tue, 2011-02-15 at 08:36 +0000, Duncan Booth wrote: > Westley Mart?nez wrote: > > >> In the end i promise they will respect you more for your honesty. And > >> it will not be a respect forged from fear, no, it will be something > >> greater! A respect forged from collaboration. A respect of comrades in > >> arms. This is the future i bring to c.l.py! > > HEIL DER FUHRER! > > Godwin was right. You lose. > > -- > Duncan Booth http://kupuguy.blogspot.com Who's more trollish? The troll, or the troll who follows him? From python at mrabarnett.plus.com Tue Feb 15 10:00:03 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 15 Feb 2011 15:00:03 +0000 Subject: interleave string In-Reply-To: <1CB62665-3B50-4A06-89D9-457B547C8A65@gmail.com> References: <1CB62665-3B50-4A06-89D9-457B547C8A65@gmail.com> Message-ID: <4D5A94F3.8050600@mrabarnett.plus.com> On 15/02/2011 09:53, Andrea Crotti wrote: > Just a curiosity not a real problem, I want to pass from a string like > > xxaabbddee > to > xx:aa:bb:dd:ee > > so every two characters insert a ":". > At the moment I have this ugly inliner > interleaved = ':'.join(orig[x:x+2] for x in range(0, len(orig), 2)) > > but also something like this would work > [''.join((x,y)) for x, y in zip(orig[0::2], orig[1::2])] > > any other ideas? interleaved = "{}{}:{}{}:{}{}:{}{}".format(*orig) From jorge.vargas at gmail.com Tue Feb 15 10:17:28 2011 From: jorge.vargas at gmail.com (Jorge Vargas) Date: Tue, 15 Feb 2011 11:17:28 -0400 Subject: How to inspect a variable (sys.modules) for changes in the execution of a program? Message-ID: Hello, I have the following situation. In a big project that involves many dependencies (and sadly some sys.module hacks) we have a bug, and it will really help if i could monitor all changes made to that variable. Is there a way to trace those changes ? From ehsan.ali01 at gmail.com Tue Feb 15 10:17:30 2011 From: ehsan.ali01 at gmail.com (Elizabeth) Date: Tue, 15 Feb 2011 07:17:30 -0800 (PST) Subject: Welcome to PhoToZfAiR Message-ID: <72bad5b3-5314-427b-bd0f-95ec427b29d7@y36g2000pra.googlegroups.com> http://www.photozfair.com http://www.photozfair.com http://www.photozfair.com free classified sites, Art/Paintings, Amazing, Celebrties, Pakistani Celebrties, Indian Celebrities, Cars, Funny, Islamic, Motorbike, Natural, World Hotels, Forex Trading, Web Hosting, Computer, Fantasy, Flowers, Food, Games, Love, Sports, From gerald.britton at gmail.com Tue Feb 15 10:19:20 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 15 Feb 2011 10:19:20 -0500 Subject: lint warnings Message-ID: >> I find: >> >> map(func, iterable) >> >> to be "neater" than: >> >> [func(item) for item in iterable] >> >> If nothing else, the "map" version is shorter. >That's only true if you wanted to call an existing function. If you wanted >to do something involving a more complex expression that you can write >inline then the list comprehension is shorter. not necessarily, no. >>> [-i if i < 0 else i for i in range(-10,0)] [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] vs. >>> map(abs, range(-10,0)) [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] > Also, as already shown, the map version is faster. >In most cases the list comprehension is faster. Try timing it. I have as have many others (including the previous poster who provided timings) >C:\Python27>python.exe lib\timeit.py -s "def double(x): return x*2" -s "data=range(10000)" "map(double, data)" >1000 loops, best of 3: 1.82 msec per loop C:\Python27>python.exe lib\timeit.py -s "def double(x): return x*2" -s "data=range(10000)" "[x*2 for x in data]" 1000 loops, best of 3: 879 usec per loop granted, but not on topic here. we're talking about map vs list comps when you want to use a function. >map is only likely to be faster if you wanted to call a function in both cases. Which is exactly the point. >f you have an expression that can be inlined you save the function call >overhead with the list comprehension. Of course, but that's not the point. -- Gerald Britton From kwa at kuwata-lab.com Tue Feb 15 10:44:52 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Wed, 16 Feb 2011 00:44:52 +0900 Subject: [ANN] Oktest 0.8.0 released - a new-style testing library Message-ID: I released Oktest 0.8.0. http://pypi.python.org/pypi/Oktest/ http://packages.python.org/Oktest/ Oktest is a new-style testing library for Python. :: from oktest import ok, NG ok (x) > 0 # same as assert_(x > 0) ok (s) == 'foo' # same as assertEqual(s, 'foo') ok (s) != 'foo' # same as assertNotEqual(s, 'foo') ok (f).raises(ValueError) # same as assertRaises(ValueError, f) ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', unicode)) NG (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', int)) ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt')) NG ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt')) See http://packages.python.org/Oktest/ for details. NOTICE!! Oktest is a young project and specification may change in the future. Enhancements and Changes ------------------------ * add ``NG()`` which is same as not_ok(). * enhanced to proive egg files for Python 3. * enhanced to support assertion method chaining. :: ok ("sos".upper()).is_a(str).matches(r'^[A-Z]+$') == "SOS" * ``ok().matches()`` can take flag parameter which is passed to re.compile(). ok ("\nSOS\n").matches(r'^[A-Z]+$', re.M) ## same as: #ok("\nSOS\n").matches(r.compile(r'^[A-Z]$', re.M)) * enhance helper methods to be available without with-statement. (this is necessary for Python 2.4 which is default version on CentOS.) from oktest.helper import chdir def fn(): ok (os.getcwd()) == "/tmp" chdir("/tmp").run(fn) ## this is same as: #with chdir("/tmp"): # ok (os.getcwd()) == "/tmp" from oktest.dummy import dummy_file def fn(): ok ("A.txt").is_file() ok (open("A.txt").read()) == "SOS" dummy_file("A.txt", "SOS").run(fun) ## this is same as: #with dummy_file("A.txt", "SOS"): # ok (open("A.txt").read()) == "SOS" * ``spec()`` now checks environment variable $SPEC. This is useful to filter test cases. ## test script from oktest import oktest, run class StrTest(object): def test_upper(self): if spec("returns upper case string"): ok ("sos".upper()) == "SOS" if spec("doesn't change non-alphabetics"): ok ("sos123<>".upper()) == "SOS123<>" if __name__ == "__main__": run() ## terminal $ SPEC="returns upper case string" python test1.py * fix ``oktest.run()`` to print correct traceback if ok() is called from nested function. * fix content of README.txt. -- regards, makoto kuwata From sturlamolden at yahoo.no Tue Feb 15 11:31:41 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Tue, 15 Feb 2011 08:31:41 -0800 (PST) Subject: Non-linear regression help in Python References: <963b83e6-ea51-4c36-b212-0deeef657630@o32g2000prb.googlegroups.com> <2b3e0b23-381f-4396-99f7-b7465b472575@x1g2000yqb.googlegroups.com> <54ebfd6f-b626-457b-bcc3-ef0b3f591dc8@k16g2000vbq.googlegroups.com> Message-ID: On 15 Feb, 05:24, Akand Islam wrote: > Dear Sturlamolden, > Thanks for reply. I will follow-up if I need further assistance. > > -- Akand You should rather use the SciPy user mailing list than comp.lang.python for this. Sturla From tjhanson at yahoo.com Tue Feb 15 12:49:08 2011 From: tjhanson at yahoo.com (Tim Hanson) Date: Tue, 15 Feb 2011 09:49:08 -0800 Subject: newbie question about PYTHONPATH Message-ID: <201102150949.08719.tjhanson@yahoo.com> I am to the point in _Learning_Python_ where functions are introduced. I decided to experiment by putting a function into a file and importing it into Idle. Of course, Idle couldn't find it, so I executed the following command in Bash: PYTHONPATH=/home/foo/prog/learning_python export PYTHONPATH env | grep PYTHONPATH ~$PYTHONPATH=/home/foo/prog/learning_python Idle still won't find it. I'm doing something wrong? From panupatc at gmail.com Tue Feb 15 13:12:46 2011 From: panupatc at gmail.com (Panupat Chongstitwattana) Date: Wed, 16 Feb 2011 01:12:46 +0700 Subject: newbie question about PYTHONPATH In-Reply-To: <201102150949.08719.tjhanson@yahoo.com> References: <201102150949.08719.tjhanson@yahoo.com> Message-ID: I think the command line should look something along this line export PYTHONPATH=$HOME/foo/prog/learning_python/: with a colon at the end. On Wed, Feb 16, 2011 at 12:49 AM, Tim Hanson wrote: > I am to the point in _Learning_Python_ ?where functions are introduced. > > I decided to experiment by putting a function into ?a file and importing it > into Idle. ?Of course, Idle couldn't find it, so I executed the following > command in Bash: > > PYTHONPATH=/home/foo/prog/learning_python > export PYTHONPATH > env | grep PYTHONPATH > > ~$PYTHONPATH=/home/foo/prog/learning_python > > Idle still won't find it. ?I'm doing something wrong? > -- > http://mail.python.org/mailman/listinfo/python-list > From clp2 at rebertia.com Tue Feb 15 13:19:07 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 15 Feb 2011 10:19:07 -0800 Subject: How to inspect a variable (sys.modules) for changes in the execution of a program? In-Reply-To: References: Message-ID: On Tue, Feb 15, 2011 at 7:17 AM, Jorge Vargas wrote: > Hello, > > I have the following situation. In a big project that involves many > dependencies (and sadly some sys.module hacks) we have a bug, and it > will really help if i could monitor all changes made to that variable. > Is there a way to trace those changes ? Is the variable's value of a mutable or immutable type? What is the variable's scope (e.g. module-level global, or object attribute)? Is the variable subject to getting rebound to an entirely new value/object? The answers to these questions will determine how much work will be required to trace "changes" to the variable. I know of no built-in way to directly do such a thing, but the underlying functionality necessary to implement such a feature (e.g. sys.settrace, __getattribute__, __setattr__) does exist. Cheers, Chris -- http://blog.rebertia.com From drsalists at gmail.com Tue Feb 15 13:28:13 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 15 Feb 2011 10:28:13 -0800 Subject: Missing SIGCHLD In-Reply-To: References: Message-ID: On Tue, Feb 15, 2011 at 2:57 AM, Dinh wrote: > Hi, > > I currently build a process management system which is able to fork child > processes (fork()) and keep them alive (waitpid() ). > > ???????????? if pid in self.current_workers: > ???????????????? os.waitpid(pid, 0) > > If a child process dies, it should trigger a SIGCHLD signal and a handler is > installed to catch the signal and start a new child process. The code is > nothing special, just can be seen in any Python tutorial you can find on the > net. > > ??????????? signal.signal(signal.SIGCHLD, self.restart_child_process) > ??????????? signal.signal(signal.SIGHUP, self.handle) # reload > ??????????? signal.signal(signal.SIGINT, self.handle) > ??????????? signal.signal(signal.SIGTERM, self.handle) > ??????????? signal.signal(signal.SIGQUIT, self.handle) > > However, this code does not always work as expected. Most of the time, it > works. When a child process exits, the master process receives a SIGCHLD and > restart_child_process() method is invoked automatically to start a new child > process. But the problem is that sometimes, I know a child process exits due > to an unexpected exception (via log file) but it seems that master process > does not know about it. No SIGCHLD and so restart_child_process() is not > triggered. Therefore, no new child process is forked. > > Could you please kindly tell me why this happens? Is there any special code > that need being installed to ensure that every dead child will be informed > correctly? > > Mac OSX 10.6 > Python 2.6.6 Hi Dinh. I've done no Mac OS/X programming, but I've done Python and *ix signals some - so I'm going to try to help you, but it'll be kind of stabbing in the dark. *ix signals have historically been rather unreliable and troublesome when used heavily. There are BSD signals, SysV signals, and POSIX signals - they all try to solve the problems in different ways. Oh, and Linux has a way of doing signals using file descriptors that apparently helps quite a bit. I'm guessing your Mac will have available BSD and maybe POSIX signals, but you might check on that. You might try using ktrace on your Mac to see if any SIGCHLD signals are getting lost (it definitely happens in some scenarios), and hopefully, which kind of (C level) signal API CPython is using on your Mac also. You might also make sure your SIGCHLD signal handler is not just waitpid'ing once per invocation, but rather doing a nonblocking waitpid in a loop until no process is found, in case signals are lost (especially if/when signals occur during signal handler processing). If the loop in your signal handler doesn't help (enough), you could also try using a nonblocking waitpid in a SIGALARM handler in addition to your SIGCHLD handler. Some signal API's want you to reenable the signal as your first action in your signal handler to shorten a race window. Hopefully Mac OS/X doesn't need this, but you might check on it. BTW, CPython signals and CPython threads don't play very nicely together; if you're combining them, you might want to study up on this. Oh, also, signals in CPython will tend to cause system calls to return without completing, and giving an EINTR in errno, and not all CPython modules will understand what to do with that. :( Sadly, many application programmers tend to ignore the EINTR possibility. HTH From wanderer at dialup4less.com Tue Feb 15 13:32:08 2011 From: wanderer at dialup4less.com (Wanderer) Date: Tue, 15 Feb 2011 10:32:08 -0800 (PST) Subject: file find skips first letter Message-ID: I'm using code def getFiles(self, fileBase): """return a list of the filenames in a director containing a base word """ allFiles = os.listdir(self.resultDir) baseFiles = [] for f in allFiles: if f.find(fileBase) > 0: baseFiles.append(f) return baseFiles but the code can't find files with fileBase in it if the fileBase starts the filename. if the filenames are rnoise##.tif and fileBase is "rnoise" the file won't be found. If fileBase is "noise" the files will be found. From mwilson at the-wire.com Tue Feb 15 13:48:10 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 15 Feb 2011 13:48:10 -0500 Subject: file find skips first letter References: Message-ID: Wanderer wrote: > I'm using code > > def getFiles(self, fileBase): > """return a list of the filenames in a director containing a > base word > """ > > allFiles = os.listdir(self.resultDir) > baseFiles = [] > for f in allFiles: > if f.find(fileBase) > 0: > baseFiles.append(f) > > return baseFiles > > but the code can't find files with fileBase in it if the fileBase > starts the filename. > > if the filenames are rnoise##.tif and fileBase is "rnoise" the file > won't be found. If fileBase is "noise" the files will be found. (untested) Try if f.find(fileBase) > -1: Mel. From alex.kapps at web.de Tue Feb 15 13:55:42 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 15 Feb 2011 19:55:42 +0100 Subject: file find skips first letter In-Reply-To: References: Message-ID: <4D5ACC2E.6070505@web.de> On 15.02.2011 19:32, Wanderer wrote: > I'm using code > > def getFiles(self, fileBase): > """return a list of the filenames in a director containing a > base word > """ > > allFiles = os.listdir(self.resultDir) > baseFiles = [] > for f in allFiles: > if f.find(fileBase)> 0: > baseFiles.append(f) > > return baseFiles > > but the code can't find files with fileBase in it if the fileBase > starts the filename. > > if the filenames are rnoise##.tif and fileBase is "rnoise" the file > won't be found. If fileBase is "noise" the files will be found. str.find() returns the index to the left-most occurrence or -1 if the substring is not found. So, if the file name starts with fileBase, find() return 0 which you filter out with your test f.find(fileBase)> 0. Either use f.find(fileBase) >= 0 or better: baseFiles = [] for f in allFiles: if fileBase in f: baseFiles.append(f) HTH From python.list at tim.thechases.com Tue Feb 15 13:59:59 2011 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 15 Feb 2011 12:59:59 -0600 Subject: file find skips first letter In-Reply-To: References: Message-ID: <4D5ACD2F.6070001@tim.thechases.com> On 02/15/2011 12:32 PM, Wanderer wrote: > if f.find(fileBase)> 0: .find() returns "-1" on failure, not 0. You want ">=" instead of just ">", or even more readably if fileBase in f: -tkc From miki.tebeka at gmail.com Tue Feb 15 14:02:22 2011 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 15 Feb 2011 11:02:22 -0800 (PST) Subject: file find skips first letter In-Reply-To: Message-ID: > def getFiles(self, fileBase): > """return a list of the filenames in a director containing a > base word > """ > ... Have a look at the glob module, it does what you want. HTH -- Miki Tebeka http://pythonwise.blogspot.com From alex.kapps at web.de Tue Feb 15 14:05:18 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 15 Feb 2011 20:05:18 +0100 Subject: newbie question about PYTHONPATH In-Reply-To: References: <201102150949.08719.tjhanson@yahoo.com> Message-ID: <4D5ACE6E.9040905@web.de> On 15.02.2011 19:12, Panupat Chongstitwattana wrote: Panupat, please don't top-post, it messes the the natural order of the discussion. Thanks. > I think the command line should look something along this line > > export PYTHONPATH=$HOME/foo/prog/learning_python/: > > with a colon at the end. Nope, the colon is only needed as a delimiter if you give more than one file. > On Wed, Feb 16, 2011 at 12:49 AM, Tim Hanson wrote: >> I am to the point in _Learning_Python_ where functions are introduced. >> >> I decided to experiment by putting a function into a file and importing it >> into Idle. Of course, Idle couldn't find it, so I executed the following >> command in Bash: >> >> PYTHONPATH=/home/foo/prog/learning_python >> export PYTHONPATH >> env | grep PYTHONPATH >> >> ~$PYTHONPATH=/home/foo/prog/learning_python >> >> Idle still won't find it. I'm doing something wrong? $ export PYTHONPATH=~/src/python/ $ idle works fine here. Where are you setting PYTHONPATH and from where do you run idle? If you set it in a terminal window, but run idle from a Desktop menu it won't work as exporting environment variables does only affect sub-processes. You might want to set PYTHONPATH in your ~/.bash_profile and then re-login. Also, how do you name your file? A Python module must end in .py HTH From python at mrabarnett.plus.com Tue Feb 15 14:11:12 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 15 Feb 2011 19:11:12 +0000 Subject: file find skips first letter In-Reply-To: References: Message-ID: <4D5ACFD0.3000209@mrabarnett.plus.com> On 15/02/2011 18:48, Mel wrote: > Wanderer wrote: > >> I'm using code >> >> def getFiles(self, fileBase): >> """return a list of the filenames in a director containing a >> base word >> """ >> >> allFiles = os.listdir(self.resultDir) >> baseFiles = [] >> for f in allFiles: >> if f.find(fileBase)> 0: >> baseFiles.append(f) >> >> return baseFiles >> >> but the code can't find files with fileBase in it if the fileBase >> starts the filename. >> >> if the filenames are rnoise##.tif and fileBase is "rnoise" the file >> won't be found. If fileBase is "noise" the files will be found. > > (untested) Try > > if f.find(fileBase)> -1: > Python is a 0-based language, so if fileBase is at the start of f then the result is 0. If fileBase isn't in f then the result is -1. An alternative is: if fileBase in f: From martin.hellwig at dcuktec.org Tue Feb 15 15:01:49 2011 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 15 Feb 2011 20:01:49 +0000 Subject: Displaying SVG in tkinter using cairo and rsvg Message-ID: Hi all, Information on using tkinter for displaying an svg image seems a bit low spread on the Internet. I recently played around with pygame and svg and realized, hold on this can be done with tk too. So I thought I post a little example for future generations :-) (and also have stored at http://dcuktec.googlecode.com/hg/source/examples/cairo_rsvg_tkinter.py). So here it is if you are interested: --- #! /usr/bin/env python """ Tkinter example for displaying SVG in a PhotoImage class using cairo and rsvg. Note that this is relatively slow, this is mainly due to converting the cairo surface data to the appropriate rgb values and putting each pixel in the PhotoImage class. """ import cairo import rsvg # I had a bit of trouble finding the rsvg python wrapper, turns out it is part # of the GnomePythonDesktop package, windows users are even less supported see: # http://cairographics.org/cairo_rsvg_and_python_in_windows/ to get it working. import Tkinter def _alpha_blending(rgba, back): "Return a rgb tuple composed from a rgba and back(ground) tuple/list." paired = zip(rgba[:-1], back) alpha = rgba[-1] tmp = list() for upper, lower in paired: blend = (((255 - alpha) * lower) + (alpha * upper)) / 255 tmp.append(blend) return(tuple(tmp)) def convert(bgra_buffer, width, height): "Convert bgra buffer to photoimage put" idx = 0 end = len(bgra_buffer) arguments = list() while idx < end: rgba = (ord(bgra_buffer[idx + 2]), ord(bgra_buffer[idx + 1]), ord(bgra_buffer[idx + 0]), ord(bgra_buffer[idx + 3])) back = (255, 255, 255) rgb = _alpha_blending(rgba, back) arguments += rgb idx += 4 template = ' '.join(height *['{%s}' % (' '.join(width*["#%02x%02x%02x"]))]) return(template % tuple(arguments)) def photoimage_from_svg(file_path_name): "Return a Tkinter.PhotoImage with the content set to the rendered SVG." svg = rsvg.Handle(file=file_path_name) width, height = svg.get_dimension_data()[:2] surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(width), int(height)) context = cairo.Context(surface) svg.render_cairo(context) image = Tkinter.PhotoImage(width=width, height=height) data = convert(surface.get_data(), width, height) image.put(data) return(image) if __name__ == '__main__': SVG = """ """ import os, tempfile # PATH = tempfile.mkstemp()[1] OPEN = open(PATH, 'w') OPEN.writelines(SVG) OPEN.close() ROOT = Tkinter.Tk() # IMAGE = photoimage_from_svg(PATH) # os.remove(PATH) BUTTON = Tkinter.Button(ROOT, image=IMAGE) BUTTON._photoimage = IMAGE BUTTON.grid() Tkinter.mainloop() --- -- mph From victorsubervi at gmail.com Tue Feb 15 15:24:57 2011 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 15 Feb 2011 16:24:57 -0400 Subject: Problem w/ MySQLdb Message-ID: Hi; I have a function that calls the following class: #!/usr/bin/python import sys,os sys.path.append(os.getcwd()) import MySQLdb from login import login import re, string def buildTableColorShortOptions(): user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor = database.cursor() cursor.execute('''create table if not exists colorShortOptions ( Color varchar(40) not null, Value bool not null default '0' ) engine=innodb''') cursor.execute("insert into colorShortOptions (Color) values ('indigo')") cursor.execute("insert into colorShortOptions (Color) values ('maroon')") cursor.execute("insert into colorShortOptions (Color) values ('violet')") cursor.execute("insert into colorShortOptions (Color) values ('tan')") cursor.execute("insert into colorShortOptions (Color) values ('lime')") cursor.execute("insert into colorShortOptions (Color) values ('blue')") cursor.execute("insert into colorShortOptions (Color) values ('fuchsia')") cursor.execute("insert into colorShortOptions (Color) values ('cobalt blue')") cursor.execute("insert into colorShortOptions (Color) values ('black')") cursor.execute("insert into colorShortOptions (Color) values ('rose pink')") cursor.execute("insert into colorShortOptions (Color) values ('air force blue')") cursor.execute("insert into colorShortOptions (Color) values ('orange')") cursor.execute("insert into colorShortOptions (Color) values ('white')") cursor.execute("insert into colorShortOptions (Color) values ('red')") cursor.execute("insert into colorShortOptions (Color) values ('yellow green')") cursor.execute("insert into colorShortOptions (Color) values ('navy blue')") cursor.execute("insert into colorShortOptions (Color) values ('salmon')") cursor.execute("insert into colorShortOptions (Color) values ('yellow')") cursor.execute("insert into colorShortOptions (Color) values ('olive')") cursor.execute("insert into colorShortOptions (Color) values ('sky blue')") cursor.execute("insert into colorShortOptions (Color) values ('silver')") cursor.execute("insert into colorShortOptions (Color) values ('gray')") cursor.execute("insert into colorShortOptions (Color) values ('green')") cursor.execute("insert into colorShortOptions (Color) values ('teal')") cursor.close() It builds the table but fails from the first insertion. Trying to insert using that code directly in MySQL does indeed work. Why? TIA, Beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From jlconlin at gmail.com Tue Feb 15 15:29:36 2011 From: jlconlin at gmail.com (Jeremy) Date: Tue, 15 Feb 2011 12:29:36 -0800 (PST) Subject: How can I define __getattr__ to operate on all items of container and pass arguments? Message-ID: I have a container object. It is quite frequent that I want to call a function on each item in the container. I would like to do this whenever I call a function on the container that doesn't exist, i.e., the container would return an attribute error. For example class Cont(object): def __init__(self): self.items = [] def contMethod(self, args): print("I'm in contMethod.") def __getattr__(self, name): for I in self.items: # How can I pass arguments to I.__dict__[name]? I.__dict__[name] >>> C = Cont() >>> # Add some items to C >>>C.contMethod() I'm in contMethod. >>>C.itemMethod('abc') ?????????? The trouble I'm getting into is that I can't pass arguments to the attributes in the contained item. In the example above, I can't pass 'abc' to the 'itemMethod' method of each item in the container. Does someone know how I can accomplish this? Thanks, Jeremy From benhoyt at gmail.com Tue Feb 15 15:32:08 2011 From: benhoyt at gmail.com (benhoyt) Date: Tue, 15 Feb 2011 12:32:08 -0800 (PST) Subject: logging module -- better timestamp accuracy on Windows Message-ID: <8d303fbd-e72b-443a-98f9-0efb52b9bbdb@glegroupsg2000goo.googlegroups.com> The Python logging module calls time.time() in LogRecord.__init__ to fetch the timestamp of the log record. However, time.time() isn't particularly accurate on Windows. We're logging start and end of our requests in our web server, which can be milliseconds apart, and the log timestamps often show up as identical, but time.clock() is telling us several milliseconds have actually elapsed. The fix is to use time.clock() if running on win32 (like "timeit" does). Here's how I've improved the accuracy for us: ----- if sys.platform == 'win32': # Running on win32, time.clock() is much more accurate than # time.time(), use it for LogRecord timestamps # Get the initial time and call time.clock() once to "start" it _start_time = time.time() time.clock() def _formatTimeAccurate(self, record, datefmt): # This is a bit nasty, as it modifies record.created and # record.msecs, but apart from monkey-patching Formatter.__init__, # how else do we do it? accurate_time = _start_time + time.clock() record.created = time.localtime(accurate_time) record.msecs = (accurate_time - int(accurate_time)) * 1000 return time.strftime(datefmt, record.created) # Override logging.Formatter's formatTime() so all logging calls # go through this logging.Formatter.formatTime = _formatTimeAccurate ----- This works, but as you can see, it's a bit hacky. Is there a better way to fix it? (I'd like the fix to affect all loggers, including the root logger.) I'm somewhat surprised that no one else has run into this before. Maybe I'm the only one who uses logging heavily under Windows ... :-) Thanks, Ben. From clp2 at rebertia.com Tue Feb 15 15:44:55 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 15 Feb 2011 12:44:55 -0800 Subject: How can I define __getattr__ to operate on all items of container and pass arguments? In-Reply-To: References: Message-ID: On Tue, Feb 15, 2011 at 12:29 PM, Jeremy wrote: > I have a container object. ?It is quite frequent that I want to call a function on each item in the container. ?I would like to do this whenever I call a function on the container that doesn't exist, i.e., the container would return an attribute error. s/function/method/ > For example > > class Cont(object): > ? ?def __init__(self): > ? ? ? ?self.items = [] > > ? ?def contMethod(self, args): > ? ? ? ?print("I'm in contMethod.") > > ? ?def __getattr__(self, name): > ? ? ? ?for I in self.items: > ? ? ? ? ? ?# How can I pass arguments to I.__dict__[name]? > ? ? ? ? ? ?I.__dict__[name] > > The trouble I'm getting into is that I can't pass arguments to the attributes in the contained item. ?In the example above, I can't pass 'abc' to the 'itemMethod' method of each item in the container. > > Does someone know how I can accomplish this? Recall that: x.y(z) is basically equivalent to: _a = x.y _a(z) So the arguments haven't yet been passed when __getattr__() is invoked. Instead, you must return a function from __getattr__(); this function will then get called with the arguments. Thus (untested): def __getattr__(self, name): def _multiplexed(*args, **kwargs): return [getattr(item, name)(*args, **kwargs) for item in self.items] return _multiplexed Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Tue Feb 15 15:53:23 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 15 Feb 2011 20:53:23 +0000 Subject: Problem w/ MySQLdb In-Reply-To: References: Message-ID: <4D5AE7C3.9050404@mrabarnett.plus.com> On 15/02/2011 20:24, Victor Subervi wrote: > Hi; > I have a function that calls the following class: > > #!/usr/bin/python > > import sys,os > sys.path.append(os.getcwd()) > import MySQLdb > from login import login > import re, string > > def buildTableColorShortOptions(): > user, passwd, db, host = login() > database = MySQLdb.connect(host, user, passwd, db) > cursor = database.cursor() > cursor.execute('''create table if not exists colorShortOptions ( > Color varchar(40) not null, > Value bool not null default '0' > ) engine=innodb''') > cursor.execute("insert into colorShortOptions (Color) values ('indigo')") > cursor.execute("insert into colorShortOptions (Color) values ('maroon')") [snip] > cursor.execute("insert into colorShortOptions (Color) values ('teal')") > cursor.close() > > It builds the table but fails from the first insertion. Trying to insert > using that code directly in MySQL does indeed work. Why? > You didn't commit the changes. From steve+comp.lang.python at pearwood.info Tue Feb 15 15:58:25 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Feb 2011 20:58:25 GMT Subject: How can I define __getattr__ to operate on all items of container and pass arguments? References: Message-ID: <4d5ae8f1$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 12:29:36 -0800, Jeremy wrote: > def __getattr__(self, name): > for I in self.items: > # How can I pass arguments to I.__dict__[name]? > I.__dict__[name] The same way you would pass arguments to any other function: with function call syntax. I.__dict__[name](arg1, arg2, arg3, ...) -- Steven From python at mrabarnett.plus.com Tue Feb 15 15:59:30 2011 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 15 Feb 2011 20:59:30 +0000 Subject: How can I define __getattr__ to operate on all items of container and pass arguments? In-Reply-To: References: Message-ID: <4D5AE932.1010102@mrabarnett.plus.com> On 15/02/2011 20:29, Jeremy wrote: > I have a container object. It is quite frequent that I want to call a function on each item in the container. I would like to do this whenever I call a function on the container that doesn't exist, i.e., the container would return an attribute error. > > For example > > class Cont(object): > def __init__(self): > self.items = [] > > def contMethod(self, args): > print("I'm in contMethod.") > > def __getattr__(self, name): > for I in self.items: > # How can I pass arguments to I.__dict__[name]? > I.__dict__[name] > > >>>> C = Cont() >>>> # Add some items to C >>>> C.contMethod() > I'm in contMethod. >>>> C.itemMethod('abc') > ?????????? > > > The trouble I'm getting into is that I can't pass arguments to the attributes in the contained item. In the example above, I can't pass 'abc' to the 'itemMethod' method of each item in the container. > > Does someone know how I can accomplish this? > Try calling it. All you're currently doing is looking it up and then discarding it. From prologic at shortcircuit.net.au Tue Feb 15 16:10:40 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Wed, 16 Feb 2011 07:10:40 +1000 Subject: Extending classes __init__behavior for newbies In-Reply-To: <4d59f687$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> <4d59f687$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Feb 15, 2011 at 1:44 PM, Steven D'Aprano wrote: > I don't. If you (generic you) have separate "write the code" and "test > the code" phases, your project is in trouble. You can probably get away > with it if it's a tiny throw-away script, but for anything more > substantial, you should be testing *as you are writing*. The two need to > go in parallel. > > I don't follow full-blown test driven development where you write the > test before you write the code, but still, the time to find out your > infrastructure is fundamentally broken is *before* you have finished it, > not three months later when you have built the entire app on top of it. Perhaps I should have clarified. I agreed only with the fact that if you spend more time in "careful" design you might spend less time fixing "defects". Agreed, test-driven development tends to lend itself to higher quality code. cheers James -- -- James Mills -- -- "Problems are solved by method" From malaclypse2 at gmail.com Tue Feb 15 16:21:47 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 15 Feb 2011 16:21:47 -0500 Subject: Problem w/ MySQLdb In-Reply-To: References: Message-ID: On Tue, Feb 15, 2011 at 3:24 PM, Victor Subervi wrote: > It builds the table but fails from the first insertion. Trying to insert > using that code directly in MySQL does indeed work. Why? In what way does it fail? Does it give you a stack trace, and if so, what does it say? Does it create the table, but not populate any data? If that's the case, you probably need to call commit() after you do your inserts. I'm not familiar with the MySQLDB module in particular, but python database adapters typically do not autocommit, unless you explicitly ask for that behavior. -- Jerry From steve+comp.lang.python at pearwood.info Tue Feb 15 16:25:53 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Feb 2011 21:25:53 GMT Subject: lint warnings References: Message-ID: <4d5aef61$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 14:32:13 +0000, Duncan Booth wrote: > >> Also, as already shown, the map version is faster. > > In most cases the list comprehension is faster. Try timing it. For an extremely specialised and minimal definition of "most cases". > C:\Python27>python.exe lib\timeit.py -s "def double(x): return x*2" -s > "data=range(10000)" "map(double, data)" 1000 loops, best of 3: 1.82 msec > per loop > > C:\Python27>python.exe lib\timeit.py -s "def double(x): return x*2" -s > "data=range(10000)" "[x*2 for x in data]" 1000 loops, best of 3: 879 > usec per loop You're not comparing apples and apples. Try calling the function double() from the list comp, instead of inlining it. Yes, if you can avoid a function call, list comps are faster than map. That's a valuable micro-optimization, although the warning about premature optimizations and small efficiencies apply. But the number of operations that can be inlined is only a vanishingly small subset of all operations you might choose to perform, and in general, map is faster than list comps with both C built-ins and pure Python functions. There's no doubt that list comps are a moderate win for readability and speed when you can inline the function as opposed to defining a lambda inside the map. But otherwise, it's a myth that map is generally slower and longer than list comps. It's usually the other way around: map(function, data) [function(x) for x in data] Even in Python3 where map becomes an iterator, it's still shorter: list(map(function, data)) [function(x) for x in data] (by two whole characters! Woo hoo, I don't need to upgrade my hard drive!!! *wink*) Conceptually, a map is a single operation. You don't have to think about the implementation, namely, "iterate over the sequence, extracting each item into a temporary variable, and call the function on that temporary variable". You just map the function to the sequence, and don't worry about the implementation. I really appreciate that. Sometimes I wish that Python would let me write function(data), although given that this would be ambiguous, map is the next best thing. > map is only likely to be faster if you wanted to call a function in both > cases. If you have an expression that can be inlined you save the > function call overhead with the list comprehension. Exactly. -- Steven From emile at fenx.com Tue Feb 15 16:29:03 2011 From: emile at fenx.com (Emile van Sebille) Date: Tue, 15 Feb 2011 13:29:03 -0800 Subject: How to inspect a variable (sys.modules) for changes in the execution of a program? In-Reply-To: References: Message-ID: On 2/15/2011 10:19 AM Chris Rebert said... > On Tue, Feb 15, 2011 at 7:17 AM, Jorge Vargas wrote: >> Hello, >> >> I have the following situation. In a big project that involves many >> dependencies (and sadly some sys.module hacks) we have a bug, and it >> will really help if i could monitor all changes made to that variable. >> Is there a way to trace those changes ? > > Is the variable's value of a mutable or immutable type? What is the > variable's scope (e.g. module-level global, or object attribute)? Is > the variable subject to getting rebound to an entirely new > value/object? > > The answers to these questions will determine how much work will be > required to trace "changes" to the variable. I know of no built-in way > to directly do such a thing, but the underlying functionality > necessary to implement such a feature (e.g. sys.settrace, > __getattribute__, __setattr__) does exist. Out of curiosity, if it's immutable, what approach might you try to capture/trace reassignment? I've got a toy tracer that breaks with simple assignment: >>> A=tracer(3) >>> A 3 >>> A+=3 value changed by 3 by add >>> A 6 >>> B=A+6 value changed by 6 by add >>> B 12 >>> B+=3 value changed by 3 by add >>> B 15 >>> A = 4 >>> A+=4 >>> Emile From mwilson at the-wire.com Tue Feb 15 16:55:24 2011 From: mwilson at the-wire.com (Mel) Date: Tue, 15 Feb 2011 16:55:24 -0500 Subject: How to inspect a variable (sys.modules) for changes in the execution of a program? References: Message-ID: Emile van Sebille wrote: > Out of curiosity, if it's immutable, what approach might you try to > capture/trace reassignment? I've got a toy tracer that breaks with > simple assignment: AFAIK you'd have to replace the namespace dictionaries with dictionary-like things that would react to rebinding. Mel. From jlconlin at gmail.com Tue Feb 15 16:58:11 2011 From: jlconlin at gmail.com (Jeremy) Date: Tue, 15 Feb 2011 13:58:11 -0800 (PST) Subject: How can I define __getattr__ to operate on all items of container and pass arguments? In-Reply-To: Message-ID: <2dc1f550-2356-40d8-a4ee-6c875668afc4@glegroupsg2000goo.googlegroups.com> On Tuesday, February 15, 2011 1:44:55 PM UTC-7, Chris Rebert wrote: > On Tue, Feb 15, 2011 at 12:29 PM, Jeremy wrote: > > I have a container object. ?It is quite frequent that I want to call a function on each item in the container. ?I would like to do this whenever I call a function on the container that doesn't exist, i.e., the container would return an attribute error. > > s/function/method/ > > > For example > > > > class Cont(object): > > ? ?def __init__(self): > > ? ? ? ?self.items = [] > > > > ? ?def contMethod(self, args): > > ? ? ? ?print("I'm in contMethod.") > > > > ? ?def __getattr__(self, name): > > ? ? ? ?for I in self.items: > > ? ? ? ? ? ?# How can I pass arguments to I.__dict__[name]? > > ? ? ? ? ? ?I.__dict__[name] > > > > > The trouble I'm getting into is that I can't pass arguments to the attributes in the contained item. ?In the example above, I can't pass 'abc' to the 'itemMethod' method of each item in the container. > > > > Does someone know how I can accomplish this? > > Recall that: > x.y(z) > is basically equivalent to: > _a = x.y > _a(z) > > So the arguments haven't yet been passed when __getattr__() is > invoked. Instead, you must return a function from __getattr__(); this > function will then get called with the arguments. Thus (untested): > > def __getattr__(self, name): > def _multiplexed(*args, **kwargs): > return [getattr(item, name)(*args, **kwargs) for item in self.items] > return _multiplexed Perfect, that's what I needed. I realized that I didn't have the arguments to the function, but couldn't figure out how to do it. This works like a charm. Thanks a lot! Jeremy From jlconlin at gmail.com Tue Feb 15 16:58:11 2011 From: jlconlin at gmail.com (Jeremy) Date: Tue, 15 Feb 2011 13:58:11 -0800 (PST) Subject: How can I define __getattr__ to operate on all items of container and pass arguments? In-Reply-To: Message-ID: <2dc1f550-2356-40d8-a4ee-6c875668afc4@glegroupsg2000goo.googlegroups.com> On Tuesday, February 15, 2011 1:44:55 PM UTC-7, Chris Rebert wrote: > On Tue, Feb 15, 2011 at 12:29 PM, Jeremy wrote: > > I have a container object. ?It is quite frequent that I want to call a function on each item in the container. ?I would like to do this whenever I call a function on the container that doesn't exist, i.e., the container would return an attribute error. > > s/function/method/ > > > For example > > > > class Cont(object): > > ? ?def __init__(self): > > ? ? ? ?self.items = [] > > > > ? ?def contMethod(self, args): > > ? ? ? ?print("I'm in contMethod.") > > > > ? ?def __getattr__(self, name): > > ? ? ? ?for I in self.items: > > ? ? ? ? ? ?# How can I pass arguments to I.__dict__[name]? > > ? ? ? ? ? ?I.__dict__[name] > > > > > The trouble I'm getting into is that I can't pass arguments to the attributes in the contained item. ?In the example above, I can't pass 'abc' to the 'itemMethod' method of each item in the container. > > > > Does someone know how I can accomplish this? > > Recall that: > x.y(z) > is basically equivalent to: > _a = x.y > _a(z) > > So the arguments haven't yet been passed when __getattr__() is > invoked. Instead, you must return a function from __getattr__(); this > function will then get called with the arguments. Thus (untested): > > def __getattr__(self, name): > def _multiplexed(*args, **kwargs): > return [getattr(item, name)(*args, **kwargs) for item in self.items] > return _multiplexed Perfect, that's what I needed. I realized that I didn't have the arguments to the function, but couldn't figure out how to do it. This works like a charm. Thanks a lot! Jeremy From victorsubervi at gmail.com Tue Feb 15 17:10:29 2011 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 15 Feb 2011 18:10:29 -0400 Subject: Problem w/ MySQLdb In-Reply-To: References: Message-ID: It's been too long since I've worked on this. Yep, I forgot to commit. Thanks, Beno On Tue, Feb 15, 2011 at 5:21 PM, Jerry Hill wrote: > On Tue, Feb 15, 2011 at 3:24 PM, Victor Subervi > wrote: > > It builds the table but fails from the first insertion. Trying to insert > > using that code directly in MySQL does indeed work. Why? > > In what way does it fail? Does it give you a stack trace, and if so, > what does it say? Does it create the table, but not populate any > data? If that's the case, you probably need to call commit() after > you do your inserts. > > I'm not familiar with the MySQLDB module in particular, but python > database adapters typically do not autocommit, unless you explicitly > ask for that behavior. > > -- > Jerry > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Tue Feb 15 17:16:26 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 15 Feb 2011 14:16:26 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> <4d59f687$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <10784cca-bc46-4972-8733-1ca54fe14786@x13g2000vbe.googlegroups.com> On Feb 14, 9:44?pm, Steven D'Aprano wrote: > On Tue, 15 Feb 2011 09:47:54 +1000, James Mills wrote: > > On Tue, Feb 15, 2011 at 9:32 AM, rantingrick > > wrote: > >> Those who write code bases should "design-in" practicality, re- > >> usability, and extendability as a forethought and NOT an afterthought. > >> Of course i am not suggesting that everyone must be clairvoyant. > >> However the vast amount of time involved in a coding project should be > >> spent in the design and testing phases and NOT actually writing code. > >> If you spend more time writing code you are not being professional, you > >> are being sloppy -- and it WILL catch up to you. > > > I actually agree with this. :) > > I don't. If you (generic you) have separate "write the code" and "test > the code" phases, your project is in trouble. You can probably get away > with it if it's a tiny throw-away script, but for anything more > substantial, you should be testing *as you are writing*. The two need to > go in parallel. My statement made no such mention of "separate phases" or how each phase should be ordered. Here, l'll paraphrase for the folks who's attention span cannot last for a full paragraph. *ahem*... "You should spend more time designing and testing code than writing it"... I hope that was clear enough for you. # In Code form. if (dev.design_time + dev.test_time) < dev.write_time: print('Good Job Skippy!') else: raise ScriptKiddieError From rantingrick at gmail.com Tue Feb 15 17:18:46 2011 From: rantingrick at gmail.com (rantingrick) Date: Tue, 15 Feb 2011 14:18:46 -0800 (PST) Subject: Extending classes __init__behavior for newbies References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> <4d59f687$0$29993$c3e8da3$5496439d@news.astraweb.com> <10784cca-bc46-4972-8733-1ca54fe14786@x13g2000vbe.googlegroups.com> Message-ID: On Feb 15, 4:16?pm, rantingrick wrote: > # In Code form. > if (dev.design_time + dev.test_time) < dev.write_time: > ? ? print('Good Job Skippy!') > else: > ? ? raise ScriptKiddieError Oops, you see what i mean!!! :-) if (dev.design_time + dev.test_time) > dev.write_time: ? ? print('Good Job Skippy!') else: ? ? raise ScriptKiddieError From python at bdurham.com Tue Feb 15 18:17:50 2011 From: python at bdurham.com (python at bdurham.com) Date: Tue, 15 Feb 2011 18:17:50 -0500 Subject: How to inspect a variable (sys.modules) for changes in the execution of a program? In-Reply-To: References: Message-ID: <1297811870.27408.1420878073@webmail.messagingengine.com> Jorge, It's been a while since I felt the need to use a Python debugger, but I could swear that most (all?) Python debuggers allow you to watch a specific variable. Check out the debuggers on the following page: http://wiki.python.org/moin/PythonDebuggers Malcolm From hpj at urpla.net Tue Feb 15 18:49:34 2011 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 16 Feb 2011 00:49:34 +0100 Subject: floating point woes Message-ID: <201102160049.35094.hpj@urpla.net> Hi, while I usually cope with the woes of floating point issues, this is one, that I didn't expect: >>> round(2.385, 2) 2.3799999999999999 Doesn't the docs say, it's rounded up for this case? Values are rounded to the closest multiple of 10 to the power minus n; if two multiples are equally close, rounding is done away from 0 Well, that one is clearly rounding down. What's up, eh, down here? Pete Python 2.6 (r26:66714, Feb 8 2011, 08:50:11) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 From clp2 at rebertia.com Tue Feb 15 18:54:47 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 15 Feb 2011 15:54:47 -0800 Subject: How to inspect a variable (sys.modules) for changes in the execution of a program? In-Reply-To: References: Message-ID: On Tue, Feb 15, 2011 at 1:29 PM, Emile van Sebille wrote: > On 2/15/2011 10:19 AM Chris Rebert said... >> On Tue, Feb 15, 2011 at 7:17 AM, Jorge Vargas >> ?wrote: >>> I have the following situation. In a big project that involves many >>> dependencies (and sadly some sys.module hacks) we have a bug, and it >>> will really help if i could monitor all changes made to that variable. >>> Is there a way to trace those changes ? >> >> Is the variable's value of a mutable or immutable type? What is the >> variable's scope (e.g. module-level global, or object attribute)? Is >> the variable subject to getting rebound to an entirely new >> value/object? >> >> The answers to these questions will determine how much work will be >> required to trace "changes" to the variable. I know of no built-in way >> to directly do such a thing, but the underlying functionality >> necessary to implement such a feature (e.g. sys.settrace, >> __getattribute__, __setattr__) does exist. > > Out of curiosity, if it's immutable, what approach might you try to > capture/trace reassignment? ?I've got a toy tracer that breaks with simple > assignment: > >>>> A=tracer(3) >>>> A > 3 >>>> A+=3 > value changed by 3 by add I was thinking of a trace (as in sys.settrace()) function that'd grab the value (or possibly object ID) of the variable every time it was called (possibly excluding certain event types) and see whether it changed vs. the value the variable had the last time it was called. This would obviously be rather inefficient. Cheers, Chris From gerald.britton at gmail.com Tue Feb 15 18:55:50 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 15 Feb 2011 18:55:50 -0500 Subject: Map vs. List Comprehensions (was "lint warnings") Message-ID: Generally, I prefer map() over list comprehensions since they are more succinct and run faster for non-trivial examples. However, I've been considering another use case related to functions in the operator module. Here are some examples: [x.method() for x in data] [x[0] for x in data] [x.attr for x in data] can be implemented as: from operator import methodcaller, itemgetter, attrgetter m = methodcaller('method') g = itemgetter(0) a = attrgetter('attr') map(m, data) map(g, data) map(a, data) I find that using map here generally is a little slower than the list comprehension, perhaps because of the extra work the operator methods have to do: >>> m = methodcaller('upper') >>> g = itemgetter(0) >>> a = attrgetter('__class__') >>> s = "a" >>> Timer('[x.upper() for x in s]', 'from __main__ import s').timeit() 1.8678569793701172 >>> Timer('map(m, s)', 'from __main__ import s, m').timeit() 2.1330718994140625 >>> Timer('[x[0] for x in s]', 'from __main__ import s').timeit() 1.6577358245849609 >>> Timer('map(g, s)', 'from __main__ import s, g').timeit() 1.8645310401916504 >>> Timer('[x.__class__ for x in s]', 'from __main__ import s').timeit() 1.7232599258422852 >>> Timer('map(a, s)', 'from __main__ import s, a').timeit() 2.4131419658660889 >>> So, what's the feeling out there? Go with map and the operators or stick with the list comps? -- Gerald Britton From andre.roberge at gmail.com Tue Feb 15 19:03:03 2011 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Tue, 15 Feb 2011 16:03:03 -0800 (PST) Subject: floating point woes In-Reply-To: Message-ID: <201c4f96-0fe9-4e7a-8a0a-e8aef96d6a12@glegroupsg2000goo.googlegroups.com> On Tuesday, February 15, 2011 7:49:34 PM UTC-4, Hans-Peter Jansen wrote: > Hi, > > while I usually cope with the woes of floating point issues, this is > one, that I didn't expect: > > >>> round(2.385, 2) > 2.3799999999999999 > > Doesn't the docs say, it's rounded up for this case? The problem is probably that 2.385 can not be represented as 2.385000000000.... >>> a = 2.385 >>> a 2.3849999999999998 Andr? > > > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 > > > Well, that one is clearly rounding down. > > What's up, eh, down here? > > Pete > > Python 2.6 (r26:66714, Feb 8 2011, 08:50:11) > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 From andre.roberge at gmail.com Tue Feb 15 19:03:03 2011 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Tue, 15 Feb 2011 16:03:03 -0800 (PST) Subject: floating point woes In-Reply-To: Message-ID: <201c4f96-0fe9-4e7a-8a0a-e8aef96d6a12@glegroupsg2000goo.googlegroups.com> On Tuesday, February 15, 2011 7:49:34 PM UTC-4, Hans-Peter Jansen wrote: > Hi, > > while I usually cope with the woes of floating point issues, this is > one, that I didn't expect: > > >>> round(2.385, 2) > 2.3799999999999999 > > Doesn't the docs say, it's rounded up for this case? The problem is probably that 2.385 can not be represented as 2.385000000000.... >>> a = 2.385 >>> a 2.3849999999999998 Andr? > > > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 > > > Well, that one is clearly rounding down. > > What's up, eh, down here? > > Pete > > Python 2.6 (r26:66714, Feb 8 2011, 08:50:11) > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 From anikom15 at gmail.com Tue Feb 15 19:03:42 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Tue, 15 Feb 2011 16:03:42 -0800 Subject: Extending classes __init__behavior for newbies In-Reply-To: <10784cca-bc46-4972-8733-1ca54fe14786@x13g2000vbe.googlegroups.com> References: <4D585984.60303@mrabarnett.plus.com> <4d5862ae$0$29967$c3e8da3$5496439d@news.astraweb.com> <0144406e-c2f7-495e-a687-0db6c7046497@s11g2000prs.googlegroups.com> <4d59f687$0$29993$c3e8da3$5496439d@news.astraweb.com> <10784cca-bc46-4972-8733-1ca54fe14786@x13g2000vbe.googlegroups.com> Message-ID: <1297814622.19175.1.camel@localhost.localdomain> On Tue, 2011-02-15 at 14:16 -0800, rantingrick wrote: > On Feb 14, 9:44 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > > On Tue, 15 Feb 2011 09:47:54 +1000, James Mills wrote: > > > On Tue, Feb 15, 2011 at 9:32 AM, rantingrick > > > wrote: > > >> Those who write code bases should "design-in" practicality, re- > > >> usability, and extendability as a forethought and NOT an afterthought. > > >> Of course i am not suggesting that everyone must be clairvoyant. > > >> However the vast amount of time involved in a coding project should be > > >> spent in the design and testing phases and NOT actually writing code. > > >> If you spend more time writing code you are not being professional, you > > >> are being sloppy -- and it WILL catch up to you. > > > > > I actually agree with this. :) > > > > I don't. If you (generic you) have separate "write the code" and "test > > the code" phases, your project is in trouble. You can probably get away > > with it if it's a tiny throw-away script, but for anything more > > substantial, you should be testing *as you are writing*. The two need to > > go in parallel. > > My statement made no such mention of "separate phases" or how each > phase should be ordered. Here, l'll paraphrase for the folks who's > attention span cannot last for a full paragraph. *ahem*... "You should > spend more time designing and testing code than writing it"... I hope > that was clear enough for you. > > # In Code form. > if (dev.design_time + dev.test_time) < dev.write_time: > print('Good Job Skippy!') > else: > raise ScriptKiddieError > > > It doesn't matter; you'll always end up spending the most time debugging the code.... From anikom15 at gmail.com Tue Feb 15 19:05:39 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Tue, 15 Feb 2011 16:05:39 -0800 Subject: floating point woes In-Reply-To: <201102160049.35094.hpj@urpla.net> References: <201102160049.35094.hpj@urpla.net> Message-ID: <1297814739.19175.2.camel@localhost.localdomain> On Wed, 2011-02-16 at 00:49 +0100, Hans-Peter Jansen wrote: > Hi, > > while I usually cope with the woes of floating point issues, this is > one, that I didn't expect: > > >>> round(2.385, 2) > 2.3799999999999999 > > Doesn't the docs say, it's rounded up for this case? > > > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 > > > Well, that one is clearly rounding down. > > What's up, eh, down here? > > Pete > > Python 2.6 (r26:66714, Feb 8 2011, 08:50:11) > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 > It's actually rounding up, but 2.38 cannot be represented precisely by floating points. This was fixed in Python 3.1. From benjamin.kaplan at case.edu Tue Feb 15 19:06:08 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 15 Feb 2011 19:06:08 -0500 Subject: floating point woes In-Reply-To: <201102160049.35094.hpj@urpla.net> References: <201102160049.35094.hpj@urpla.net> Message-ID: On Tue, Feb 15, 2011 at 6:49 PM, Hans-Peter Jansen wrote: > Hi, > > while I usually cope with the woes of floating point issues, this is > one, that I didn't expect: > >>>> round(2.385, 2) > 2.3799999999999999 > > Doesn't the docs say, it's rounded up for this case? > > > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 > > > Well, that one is clearly rounding down. > > What's up, eh, down here? > > Pete > The number you are rounding is not 2.385. It is not possible to represent that number in binary, just like you cannot represent the value 1/3 in decimal. So instead, you're using the nearest approximation that an IEEE 754 Double-Precision Floating Point number can get you, which happens to be about 2.3849999999999998. And that rounds down to 2.38. Which also cannot be precisely represented in binary, so you get 2.3799999999999999 instead. From ian.g.kelly at gmail.com Tue Feb 15 19:09:11 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 15 Feb 2011 17:09:11 -0700 Subject: floating point woes In-Reply-To: <201102160049.35094.hpj@urpla.net> References: <201102160049.35094.hpj@urpla.net> Message-ID: On Tue, Feb 15, 2011 at 4:49 PM, Hans-Peter Jansen wrote: > Hi, > > while I usually cope with the woes of floating point issues, this is > one, that I didn't expect: > >>>> round(2.385, 2) > 2.3799999999999999 > > Doesn't the docs say, it's rounded up for this case? > > > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 > > > Well, that one is clearly rounding down. > > What's up, eh, down here? Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 2.385 2.3849999999999998 Looks to me like it's working as expected... From clp2 at rebertia.com Tue Feb 15 19:09:58 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 15 Feb 2011 16:09:58 -0800 Subject: floating point woes In-Reply-To: <201102160049.35094.hpj@urpla.net> References: <201102160049.35094.hpj@urpla.net> Message-ID: On Tue, Feb 15, 2011 at 3:49 PM, Hans-Peter Jansen wrote: > Hi, > > while I usually cope with the woes of floating point issues, this is > one, that I didn't expect: > >>>> round(2.385, 2) > 2.3799999999999999 > > Doesn't the docs say, it's rounded up for this case? > > > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 > > > Well, that one is clearly rounding down. > > What's up, eh, down here? http://docs.python.org/library/functions.html#round : """ Note: The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it?s a result of the fact that most decimal fractions can?t be represented exactly as a float. See "Floating Point Arithmetic: Issues and Limitations"[1] for more information. """ [1]: http://docs.python.org/tutorial/floatingpoint.html And indeed: >>> from decimal import Decimal >>> Decimal(2.385) Decimal('2.3849999999999997868371792719699442386627197265625') Which, rounded to 2 decimal places, gives us 2.38, which is in turn approximated as: 2.37999999999999989341858963598497211933135986328125 I encourage reading [1]. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Tue Feb 15 19:24:59 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 15 Feb 2011 16:24:59 -0800 Subject: floating point woes In-Reply-To: References: <201102160049.35094.hpj@urpla.net> Message-ID: On Tue, Feb 15, 2011 at 4:09 PM, Chris Rebert wrote: > On Tue, Feb 15, 2011 at 3:49 PM, Hans-Peter Jansen wrote: >> Hi, >> >> while I usually cope with the woes of floating point issues, this is >> one, that I didn't expect: >> >>>>> round(2.385, 2) >> 2.3799999999999999 >> >> Doesn't the docs say, it's rounded up for this case? >> >> >> Values are rounded to the closest multiple of 10 to the power minus n; >> if two multiples are equally close, rounding is done away from 0 >> >> >> Well, that one is clearly rounding down. >> >> What's up, eh, down here? > > http://docs.python.org/library/functions.html#round : > """ > Note: The behavior of round() for floats can be surprising: for > example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This > is not a bug: it?s a result of the fact that most decimal fractions > can?t be represented exactly as a float. See "Floating Point > Arithmetic: Issues and Limitations"[1] for more information. > """ > [1]: http://docs.python.org/tutorial/floatingpoint.html > > And indeed: >>>> from decimal import Decimal >>>> Decimal(2.385) > Decimal('2.3849999999999997868371792719699442386627197265625') > > Which, rounded to 2 decimal places, gives us 2.38, which is in turn > approximated as: [*whacks forehead hard*] Nevermind. - Chris From hpj at urpla.net Tue Feb 15 20:02:49 2011 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 16 Feb 2011 02:02:49 +0100 Subject: floating point woes In-Reply-To: References: <201102160049.35094.hpj@urpla.net> Message-ID: <201102160202.49897.hpj@urpla.net> On Wednesday 16 February 2011, 01:06:08 Benjamin Kaplan wrote: > On Tue, Feb 15, 2011 at 6:49 PM, Hans-Peter Jansen wrote: > > Hi, > > > > while I usually cope with the woes of floating point issues, this > > is > > > > one, that I didn't expect: > >>>> round(2.385, 2) > > > > 2.3799999999999999 > > > > Doesn't the docs say, it's rounded up for this case? > > > > > > Values are rounded to the closest multiple of 10 to the power minus > > n; if two multiples are equally close, rounding is done away from 0 > > > > > > Well, that one is clearly rounding down. > > > > What's up, eh, down here? > > > > Pete > > The number you are rounding is not 2.385. It is not possible to > represent that number in binary, just like you cannot represent the > value 1/3 in decimal. So instead, you're using the nearest > approximation that an IEEE 754 Double-Precision Floating Point number > can get you, which happens to be about 2.3849999999999998. And that > rounds down to 2.38. Which also cannot be precisely represented in > binary, so you get 2.3799999999999999 instead. Thanks for the explanation, Benjamin. Not that I like it, but anyway. If I hadn't quitted smoking a long time ago, I would go and ask, what these engineers smoked during the course of inventing this sh*t. Even more probably, they took way too much of a special form of lysergic acid. OTOH, cdecimals, as in Stefan Krah's package are long overdue to get into the core. Pete From hpj at urpla.net Tue Feb 15 20:18:40 2011 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 16 Feb 2011 02:18:40 +0100 Subject: floating point woes In-Reply-To: References: <201102160049.35094.hpj@urpla.net> Message-ID: <201102160218.41100.hpj@urpla.net> On Wednesday 16 February 2011, 01:24:59 Chris Rebert wrote: > On Tue, Feb 15, 2011 at 4:09 PM, Chris Rebert wrote: > > On Tue, Feb 15, 2011 at 3:49 PM, Hans-Peter Jansen wrote: > >> Hi, > >> > >> while I usually cope with the woes of floating point issues, this > >> is > >> > >> one, that I didn't expect: > >>>>> round(2.385, 2) > >> > >> 2.3799999999999999 > >> > >> Doesn't the docs say, it's rounded up for this case? > >> > >> > >> Values are rounded to the closest multiple of 10 to the power > >> minus n; if two multiples are equally close, rounding is done away > >> from 0 > >> > >> Well, that one is clearly rounding down. > >> > >> What's up, eh, down here? > > > > http://docs.python.org/library/functions.html#round : > > """ > > Note: The behavior of round() for floats can be surprising: for > > example, round(2.675, 2) gives 2.67 instead of the expected 2.68. > > This is not a bug: it?s a result of the fact that most decimal > > fractions can?t be represented exactly as a float. See "Floating > > Point Arithmetic: Issues and Limitations"[1] for more information. > > """ > > [1]: http://docs.python.org/tutorial/floatingpoint.html > > > > And indeed: > >>>> from decimal import Decimal > >>>> Decimal(2.385) > > > > Decimal('2.3849999999999997868371792719699442386627197265625') > > > > Which, rounded to 2 decimal places, gives us 2.38, which is in turn > > approximated as: If that only wouldn't be so arkward to use: >>> from cdecimal import Decimal, ROUND_HALF_UP >>> d = Decimal("2.385") >>> d Decimal('2.385') >>> d.quantize(Decimal('1.00')) Decimal('2.38') hrmpf. >>> d.quantize(Decimal('1.00'), ROUND_HALF_UP) Decimal('2.39') Oh, well. This is a bit too Cobolesque. (Yes, sure, I know, I can define any context, I like.) > [*whacks forehead hard*] > Nevermind. Too true. > - Chris Pete From spam at uce.gov Tue Feb 15 21:23:39 2011 From: spam at uce.gov (spam at uce.gov) Date: Tue, 15 Feb 2011 19:23:39 -0700 Subject: return an object of a different class Message-ID: How can I do something like this in python: #!/usr/bin/python3.1 class MyNumbers: def __init__(self, n): self.original_value = n if n <= 100: self = SmallNumers(self) else: self = BigNumbers(self) class SmallNumbers: def __init__(self, n): self.size = 'small' class BigNumbers: def __init__(self, n): self.size = 'big' t = MyNumbers(200) When I do type(t) it says MyNumbers, while I'd want it to be BigNumbers, because BigNumbers and SmallNumbers will have different methods etc... Do I need to use metaclasses? Thanks. -- Yves. http://www.SollerS.ca/ http://blog.zioup.org/ From python at mrabarnett.plus.com Tue Feb 15 21:32:12 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 16 Feb 2011 02:32:12 +0000 Subject: return an object of a different class In-Reply-To: References: Message-ID: <4D5B372C.4070906@mrabarnett.plus.com> On 16/02/2011 02:23, spam at uce.gov wrote: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > def __init__(self, n): > self.original_value = n > if n <= 100: > self = SmallNumers(self) > else: > self = BigNumbers(self) > > class SmallNumbers: > def __init__(self, n): > self.size = 'small' > > class BigNumbers: > def __init__(self, n): > self.size = 'big' > > t = MyNumbers(200) > > > When I do type(t) it says MyNumbers, while I'd want it to be BigNumbers, > because BigNumbers and SmallNumbers will have different methods etc... > > Do I need to use metaclasses? > Why not just make MyNumbers a function? From aitilang at 163.com Tue Feb 15 21:32:57 2011 From: aitilang at 163.com (aitilang) Date: Wed, 16 Feb 2011 10:32:57 +0800 Subject: return an object of a different class In-Reply-To: References: Message-ID: <4D5B3759.3040107@163.com> er................ I think you need a NumberFactory that makes SmallNumber and BigNumber according to the initial value. ? 2011-2-16 10:23, spam at uce.gov ??: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > def __init__(self, n): > self.original_value = n > if n <= 100: > self = SmallNumers(self) > else: > self = BigNumbers(self) > > class SmallNumbers: > def __init__(self, n): > self.size = 'small' > > class BigNumbers: > def __init__(self, n): > self.size = 'big' > > t = MyNumbers(200) > > > When I do type(t) it says MyNumbers, while I'd want it to be > BigNumbers, because BigNumbers and SmallNumbers will have different > methods etc... > > Do I need to use metaclasses? > > Thanks. From ben+python at benfinney.id.au Tue Feb 15 21:35:27 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 16 Feb 2011 13:35:27 +1100 Subject: return an object of a different class References: Message-ID: <87fwrohfkg.fsf@benfinney.id.au> spam at uce.gov writes: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > def __init__(self, n): > self.original_value = n > if n <= 100: > self = SmallNumers(self) > else: > self = BigNumbers(self) A class defines a type of object. If you don't actually want instances of that class, then you don't really want a class. > class SmallNumbers: > def __init__(self, n): > self.size = 'small' > > class BigNumbers: > def __init__(self, n): > self.size = 'big' > > t = MyNumbers(200) > > > When I do type(t) it says MyNumbers, while I'd want it to be > BigNumbers, because BigNumbers and SmallNumbers will have different > methods etc... > > Do I need to use metaclasses? You could. Or you could simply use a factory function:: def make_number(value): if value <= 100: result = SmallNumbers(value) else: result = BigNumbers(value) result.original_value = value return result t = make_number(200) -- \ ?Programs must be written for people to read, and only | `\ incidentally for machines to execute.? ?Abelson & Sussman, | _o__) _Structure and Interpretation of Computer Programs_ | Ben Finney From wuwei23 at gmail.com Tue Feb 15 21:45:52 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 15 Feb 2011 18:45:52 -0800 (PST) Subject: return an object of a different class References: Message-ID: On Feb 16, 12:23?pm, s... at uce.gov wrote: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > ? ?def __init__(self, n): > ? ? ?self.original_value = n > ? ? ?if n <= 100: > ? ? ? ?self = SmallNumers(self) > ? ? ?else: > ? ? ? ?self = BigNumbers(self) > > class SmallNumbers: > ? ?def __init__(self, n): > ? ? ?self.size = 'small' > > class BigNumbers: > ? ?def __init__(self, n): > ? ? ?self.size = 'big' > > t = MyNumbers(200) > > When I do type(t) it says MyNumbers, while I'd want it to be BigNumbers, > because BigNumbers and SmallNumbers will have different methods etc... Firstly, does MyNumbers _have_ to be a class? Or would a function acting as a class factory be sufficient? Otherwise, you can change the class of an object, even within its own methods: class MyNumbers(object): def __init__(self, n = 0): self.original_value = n self.__class__ = BigNumbers if n > 100 else SmallThing class BigNumbers(MyNumbers): size = 'big' class SmallNumbers(MyNumbers): size = 'small' >>> from test import * >>> s = MyNumbers(50) >>> b = MyNumbers(200) >>> type(s) >>> s.size 'small' >>> type(b) >>> b.size 'big' Hope this helps. From wuwei23 at gmail.com Tue Feb 15 21:48:46 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 15 Feb 2011 18:48:46 -0800 (PST) Subject: return an object of a different class References: Message-ID: <30e587fc-7a24-4d3c-96ea-ce83a4003e9d@f36g2000pri.googlegroups.com> alex23 wrote: > ? ? self.__class__ = BigNumbers if n > 100 else SmallThing That should, of course, be SmallNumbers :) From rridge at csclub.uwaterloo.ca Tue Feb 15 22:11:31 2011 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Tue, 15 Feb 2011 22:11:31 -0500 Subject: logging module -- better timestamp accuracy on Windows References: <8d303fbd-e72b-443a-98f9-0efb52b9bbdb@glegroupsg2000goo.googlegroups.com> Message-ID: benhoyt wrote: >This works, but as you can see, it's a bit hacky. Is there a better way to = >fix it? (I'd like the fix to affect all loggers, including the root logger.= >) A simpler solution would be to caclulate the time it takes to the handle the request using time.clock() and include it in the log message. Something like: timer = time.time if sys.platform == 'win32': timer = time.clock def handler(...): start = timer() ... logging.debug("processing time %.0fms", (timer() - start) * 1000) Saves you from having to do the math in your head when you look at the logs. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From wuwei23 at gmail.com Tue Feb 15 22:39:30 2011 From: wuwei23 at gmail.com (alex23) Date: Tue, 15 Feb 2011 19:39:30 -0800 (PST) Subject: interleave string References: Message-ID: Andrea Crotti wrote: > At the moment I have this ugly inliner > ? ? ? ? interleaved = ':'.join(orig[x:x+2] for x in range(0, len(orig), 2)) I actually prefer this over every other solution to date. If you feel its too much behaviour in one line, I sometimes break it out into separate values to provide some in-code documentation: >>> s = "xxaabbddee" >>> get_two_chars_at = lambda i: s[i:i+2] >>> string_index = xrange(0, len(s), 2) >>> ':'.join(get_two_chars_at(i) for i in string_index) 'xx:aa:bb:dd:ee' From invalid at invalid.invalid Tue Feb 15 23:07:34 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Feb 2011 04:07:34 +0000 (UTC) Subject: floating point woes References: <201102160049.35094.hpj@urpla.net> Message-ID: On 2011-02-16, Ian Kelly wrote: > On Tue, Feb 15, 2011 at 4:49 PM, Hans-Peter Jansen wrote: >> >> while I usually cope with the woes of floating point issues, this is >> one, that I didn't expect: >> >>>>> round(2.385, 2) >> 2.3799999999999999 >> >> Doesn't the docs say, it's rounded up for this case? [...] > Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> 2.385 > 2.3849999999999998 > > Looks to me like it's working as expected... Well, it's working as it's supposed to... Whether it's working as expected depends on the user. :) -- Grant From invalid at invalid.invalid Tue Feb 15 23:18:40 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Feb 2011 04:18:40 +0000 (UTC) Subject: floating point woes References: <201102160049.35094.hpj@urpla.net> Message-ID: On 2011-02-16, Hans-Peter Jansen wrote: > Thanks for the explanation, Benjamin. Not that I like it, but anyway. > If I hadn't quitted smoking a long time ago, I would go and ask, what > these engineers smoked during the course of inventing this sh*t. Like most tools, IEEE floating point works brilliantly for what it was intended when used by people who know how to use it. The problem is that it's used for all sorts of things it shouldn't be by people who don't understand how it works (again, like most tools). The problem is that it _appears_ easy to use, but it actually takes some study and effort to use it right. Back in the days before FP hardware was affordable, it used to be fairly common for BCD to be the default FP representation in many non-Fortran languages (BASIC, Pascal, etc.). I think that probably provided a lot fewer surprises to most users. > Even more probably, they took way too much of a special form of > lysergic acid. > > OTOH, cdecimals, as in Stefan Krah's package are long overdue to get > into the core. There probably needs to be some sort of BCD FP option for the casual user since most people would probably be better off with BCD. Those who need HW FP probably know it (and might even know how to use it). [I may have just barely passed undergrad numerical analysis, but I learned enough to know how ignorant I was.] -- Grant From me at davecotter.com Tue Feb 15 23:50:11 2011 From: me at davecotter.com (dave) Date: Tue, 15 Feb 2011 20:50:11 -0800 (PST) Subject: unicode shutil.copy() changes a file name during copy? Message-ID: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> i'm on windows, using active python 2.7.1 i've written a script to copy a folder of files to dest folder.. one if the files in this folder has the section symbol (?, '\x15') as part of the file name shutil.copy(src_file, dst_file) "can't find the file specified" when it does the os.chmod() part, can't find dest file, cuz the file got copied with "_" in place of the section symbol. gar. Traceback (most recent call last): File "../../python/post_build.py", line 159, in main(proB, debugB) File "../../python/post_build.py", line 105, in main paths.copy_folder(srcResFolder + 'Export', destRes + '/codecs/ Export') File "F:\Users\davec\Developer\depot\kJams\Development\xplat\python \paths.py", line 77, in copy_folder copy_folder(srcPath, new_dst_obj) File "F:\Users\davec\Developer\depot\kJams\Development\xplat\python \paths.py", line 80, in copy_folder copy_file(srcPath, new_dst_obj) File "F:\Users\davec\Developer\depot\kJams\Development\xplat\python \paths.py", line 37, in copy_file shutil.copy(src_file, dst_file) File "C:\Python27\lib\shutil.py", line 117, in copy copymode(src, dst) File "C:\Python27\lib\shutil.py", line 90, in copymode os.chmod(dst, mode) WindowsError: [Error 2] The system cannot find the file specified: 'build\\kJams Pro Debug.app/Contents/Resources/codecs/Export/Codec [MooV]/Animation \xa7 AAC.rtm' if i replace that with shutil.copyfile(src_file, dst_file) it "works", again by replacing the section symbol with underbar. but that leaves me to call os.chmod() myself, which of course fails because of the character substitution. i'm gathering the list of files to iterate over the folder via: fileList = os.listdir(src_dir) for fileName in fileList: and yes, src_dir is "unicode". but the fileName when i print it shows the degree symbol (?, '\xa7') in place of the section symbol. i suspect it's a 'dbcs' or 'latin_1' problem? this same exact python code works on the mac (it's utf8 down to the metal) and, get this, it works when running Windows under Parallels Desktop. It fails only when running Windows natively. I can't see how that makes a difference. i can give a whole lot more info, but i just want to know if i'm trying to do something impossible. If this seems strange to y'all gladly i'll fill in all the details, but hoping it can be short circuited by someone going "ah hah! you have to do such and so". From chardster at gmail.com Wed Feb 16 00:05:32 2011 From: chardster at gmail.com (Richard Thomas) Date: Tue, 15 Feb 2011 21:05:32 -0800 (PST) Subject: return an object of a different class References: Message-ID: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> On Feb 16, 2:23?am, s... at uce.gov wrote: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > ? ?def __init__(self, n): > ? ? ?self.original_value = n > ? ? ?if n <= 100: > ? ? ? ?self = SmallNumers(self) > ? ? ?else: > ? ? ? ?self = BigNumbers(self) > > class SmallNumbers: > ? ?def __init__(self, n): > ? ? ?self.size = 'small' > > class BigNumbers: > ? ?def __init__(self, n): > ? ? ?self.size = 'big' > > t = MyNumbers(200) > > When I do type(t) it says MyNumbers, while I'd want it to be BigNumbers, > because BigNumbers and SmallNumbers will have different methods etc... > > Do I need to use metaclasses? > > Thanks. > -- > Yves. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?http://www.SollerS.ca/ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?http://blog.zioup.org/ If you don't want to use a factory function I believe you can do this: class MyNumber(object): def __new__(cls, n): if n <= 100: cls = SmallNumbers else: cls = BigNumbers return object.__new__(cls, n) ... Chard. From spam at uce.gov Wed Feb 16 00:06:22 2011 From: spam at uce.gov (spam at uce.gov) Date: Tue, 15 Feb 2011 22:06:22 -0700 Subject: return an object of a different class In-Reply-To: References: Message-ID: On 11-02-15 07:45 PM, alex23 wrote: > > Firstly, does MyNumbers _have_ to be a class? Or would a function > acting as a class factory be sufficient? Yes it does. I didn't explain my problem, chose a terrible example. This is more what I'm trying to do: class thingy: def __init__(self, athingy): self.basic_extract() if self.sortof = def basic_extract(self): do a bunch of things self.sortof = .. def general_method(self) class ThingyTypeA: def __init__(self): further_extract() class ThingyTypeB: def __init__(self): further_extract() > > Otherwise, you can change the class of an object, even within its own > methods: And then I just call __init__ method? > > class MyNumbers(object): > def __init__(self, n = 0): > self.original_value = n > self.__class__ = BigNumbers if n> 100 else SmallThing self.__init__() > > class BigNumbers(MyNumbers): def __init__(self): > size = 'big' self.newvalue = self.original_value * y > > class SmallNumbers(MyNumbers): def __init__(self): > size = 'small' self.newvalue = self.original_value * x > > Hope this helps. Yes, thanks! -- Yves. http://www.SollerS.ca/ http://blog.zioup.org/ From spam at uce.gov Wed Feb 16 00:17:13 2011 From: spam at uce.gov (spam at uce.gov) Date: Tue, 15 Feb 2011 22:17:13 -0700 Subject: return an object of a different class In-Reply-To: References: Message-ID: I didn't explain my problem, chose a terrible example. This is more what I'm trying to do: class thingy: def __init__(self, athingy): self.basic_extract() if self.typeof = A .../... def basic_extract(self): # complicated logic to extract data out of the thingy here # and set a bunch of values base on the data we extract self.size = xxx self.typeof = yyy self.weight = zzz def general_method(self) # Method that can be used on both types of thingy class ThingyTypeA: def __init__(self): # do some further extraction specific to type A further_extract() class ThingyTypeB: def __init__(self): # do some further extraction specific to type B further_extract() -- Yves. http://www.SollerS.ca/ http://blog.zioup.org/ From askutt at gmail.com Wed Feb 16 00:22:32 2011 From: askutt at gmail.com (Adam Skutt) Date: Tue, 15 Feb 2011 21:22:32 -0800 (PST) Subject: Missing SIGCHLD References: Message-ID: On Feb 15, 1:28?pm, Dan Stromberg wrote: > *ix signals have historically been rather unreliable and troublesome > when used heavily. > > There are BSD signals, SysV signals, and POSIX signals - they all try > to solve the problems in different ways. No, there are just signals[1]. There are several different APIs for handling signals, depending on the situation, but they're all driving the same functionality underneath the covers. These days, only sigaction(2) is remotely usable (in C) for installing handlers and all the other APIs should normally be ignored. > You might also make sure your SIGCHLD signal handler is not just > waitpid'ing once per invocation, but rather doing a nonblocking > waitpid in a loop until no process is found, in case signals are lost > (especially if/when signals occur during signal handler processing). This is the most likely the issue. Multiple instances of the same pending signals are coalesced together automatically. It would also help to make sure the signal handler just sets a flag, within the application's main loop it should then respond to that flag appropriately. Running anything inside a signal handler is a recipe for disaster. Also, SIGCHLD handlers may not get reinstalled on some operating systems (even in Python), so the application code needs to reinstall it. If not done within the signal handler, this can caused signals to get "lost". That being said, I'd just spawn a thread and wait there and avoid SIGCHLD altogether. It's typically not worth the hassle. > Oh, also, signals in CPython will tend to cause system calls to return > without completing, and giving an EINTR in errno, and not all CPython > modules will understand what to do with that. ?:( ?Sadly, many > application programmers tend to ignore the EINTR possibility. This can be disabled by signal.siginterrupt(). Regardless, the signal handling facilities provided by Python are rather poor. Adam [1] Ok, I lied, there's regular signals and realtime signals, which have a few minor differences. From mwilson at the-wire.com Wed Feb 16 00:39:14 2011 From: mwilson at the-wire.com (Mel) Date: Wed, 16 Feb 2011 00:39:14 -0500 Subject: floating point woes References: Message-ID: Hans-Peter Jansen wrote: > Hi, > > while I usually cope with the woes of floating point issues, this is > one, that I didn't expect: > >>>> round(2.385, 2) > 2.3799999999999999 > > Doesn't the docs say, it's rounded up for this case? > > > Values are rounded to the closest multiple of 10 to the power minus n; > if two multiples are equally close, rounding is done away from 0 > > > Well, that one is clearly rounding down. > > What's up, eh, down here? 2.385 isn't really 2.385: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> repr (2.385) '2.3849999999999998' >>> so it correctly rounded down. You need to use Decimal numbers if you want numbers that behave the way they look. Mel. From ben+python at benfinney.id.au Wed Feb 16 01:03:20 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 16 Feb 2011 17:03:20 +1100 Subject: return an object of a different class References: Message-ID: <87bp2ch5xz.fsf@benfinney.id.au> spam at uce.gov writes: > I didn't explain my problem, chose a terrible example. This is more > what I'm trying to do: Unfortunately, it's still very contrived, and the names don't give any suggestion as to what you're trying to achieve. Can you improve on that? > class ThingyTypeA: > def __init__(self): > # do some further extraction specific to type A > further_extract() > > > class ThingyTypeB: > def __init__(self): > # do some further extraction specific to type B > further_extract() Perhaps you want those classes to inherit from your base class. Have you done the Python tutorial? It covers inheritance and how to use it. -- \ ?Are you pondering what I'm pondering?? ?I think so, Brain, but | `\ I don't think Kay Ballard's in the union.? ?_Pinky and The | _o__) Brain_ | Ben Finney From bugcy013 at gmail.com Wed Feb 16 01:05:51 2011 From: bugcy013 at gmail.com (Bugcy 013) Date: Wed, 16 Feb 2011 11:35:51 +0530 Subject: Python-GUI Button arrangement Help In-Reply-To: References: Message-ID: Dear all, I am new to python programming, I am developing some small application, user agreement using Tkinter , totally my application having four buttons AGREE, DISAGREE , QUIT ,NEXT. AGREE--->>Enable the Next Button DISAGREE--->> One Waring?message?will show up yes are no QUIT ---->> Quit the application Next -->>Calling one python script exit the GUI I have created application all working fine button will show up the top of the screen.. i want show bottom of the frame... plz... Help me... #! /usr/bin/python from Tkinter import Tk, RIGHT, BOTH, RAISED from ttk import Frame, Button, Style import sys import os sys.path[:0] = ['../../..'] import string import Tkinter import Pmw import wx from Tkinter import * import tkMessageBox import gtk b1 = 'True' c1 = 'False' a1 = 1 class Example(Frame): ? ?def __init__(self1, parent): ? ? ? ?Frame.__init__(self1, parent) ? ? ? ?self1.parent = parent ? ? ? ?self1.initUI() ? ? ? ?#fixedFont = Pmw.logicalfont('Fixed') ? ? ? ?self1.st = Pmw.ScrolledText(parent, ? ? ? ? ? ? ? ?labelpos = 'n', ? ? ? ? ? ? ? ?label_text='User Aggrement', ? ? ? ? ? ? ? ?usehullsize = 1, ? ? ? ? ? ? ? ?hull_width = 600, ? ? ? ? ? ? ? ?hull_height = 400, ? ? ? ? ? ? ? ?text_wrap='none', ? ? ? ? ? ? ? ?#text_font = fixedFont, ? ? ? ? ? ? ? ?text_padx = 4, ? ? ? ? ? ? ? ?text_pady = 4, ? ? ? ?) ? ? ? ?self1.st.importfile('python.txt'); ? ? ? ?self1.st.pack(padx = 5, pady = 5, fill = 'both', expand = 1) ? ? ? ?# Prevent users' modifying text and headers ? ? ? ?self1.st.configure(text_state = 'disabled') ? ?def initUI(self1): ? ? ? ?self1.parent.title("User Aggrement") ? ? ? ?self1.style = Style() ? ? ? ?self1.style.theme_use("default") ? ? ? ?frame = Frame(self1, relief=RAISED, borderwidth=.5) ? ? ? ?frame.pack(fill=BOTH, expand=1) ? ? ? ?self1.pack(fill=BOTH, expand=1) ? ? ? ?def buttonPress(var): ? ? ? ? ? ? ? ?#print 'The "%s" button was pressed' % var ? ? ? ? ? ? ? ?if var == 'ok': ? ? ? ? ? ? ? ? ? ? ? ?#os.system("ls -l") & os.system("man man") ? ? ? ? ? ? ? ? ? ? ? ?widget.configure(state=NORMAL) ? ? ? ? ? ? ? ?elif var == 'dhana': ? ? ? ? ? ? ? ? ? ? ? ?os.system("top") & exit() ? ? ? ? ? ? ? ?elif var == 'close': ? ? ? ? ? ? ? ? ? ? ? ?a1 = tkMessageBox.askyesno("DisAgree", "Do you really wish to Disagree?" ) ? ? ? ? ? ? ? ? ? ? ? ?#print a1 ? ? ? ? ? ? ? ?if a1 == 1: ? ? ? ? ? ? ? ? ? ? ? ?exit() ? ? ? ? ? ? ? ?else: ? ? ? ? ? ? ? ? ? ? ? ?sys.exit ? ? ? ?widget = Tkinter.Button(self1, text='Next',command = lambda b='dhana': ? ? buttonPress(b) ) ? ? ? ?widget.pack(side=RIGHT, padx=5, pady=5) ? ? ? ?widget.configure(state=DISABLED ) ? ? ? ?def defaultKey(event): ? ? ? ? ? ? ? ?def make_widgets(self1): ? ? ? ? ? ? ? ? ? ? ? ?buttonBox.invoke() ? ? ? ? ? ? ? ? ? ? ? ?self1.make_widgets() ? ? ? ? ? ? ? ?root = Tkinter.tk() ? ? ? ?okButton = Tkinter.Button(self1, text="Quit",command = sys.exit ?, font=('Arial', 10), fg="black") ? ? ? ?okButton.pack(side=RIGHT, padx=5, pady=5) ? ? ? ?CloseButton = Tkinter.Button(self1, text="DisAgree",command = lambda b='close': ? ? buttonPress(b) , font=('Arial', 10), fg="black") ? ? ? ?CloseButton.pack(side=RIGHT, padx=5, pady=5) ? ? ? ?okButton = Tkinter.Button(self1, text="Agree",command = lambda b='ok': ? ? buttonPress(b) , font=('Arial', 10), fg="black") ? ? ? ?okButton.pack(side=RIGHT, padx=5, pady=5) ? ? ? ?okButton.focus_force() ? ? ? ?#self1.mainloop() ?######################################################################################################################################## def main(): ? ?root = Tkinter.Tk() ? ?root.geometry("600x400+30+30") ? ?app = Example(root) ? ?root.mainloop() if __name__ == '__main__': ? ?main() -- Did I learn something today? If not, I wasted it. From zhzhqiang at gmail.com Wed Feb 16 01:24:40 2011 From: zhzhqiang at gmail.com (fireinice) Date: Tue, 15 Feb 2011 22:24:40 -0800 (PST) Subject: Is this a bug of str.join? Message-ID: <289c9fbb-2163-4411-8fc4-9c912ab2b927@x13g2000vbe.googlegroups.com> Hi, all I'm just working around to generate some fake file for parsing. and I notice some weired thing happen. time = str(random.randint(1000000000000000, 9999999999999999)) s_id = str(random.randint(1000000000000000, 9999999999999999)) p_id = str(random.randint(1000000000000000, 9999999999999999)) a_id = str(random.randint(1000000000000000, 9999999999999999)) s = "test" a = [time, s_id, p_id, a_id, s] print '\t'.join(a) the output is: 3107903582321032 6101282916386924 719897196119318 1780339444980186test you can notice that there is no tab between a_id and s if I switch a_id and p_id, it still happen, but if I delete one of ids, the problem gone. I tried this with python2.6 from debian source and python2.3 which I compiled from source. the result are both the same. What happened to str.join? thanks From bugcy013 at gmail.com Wed Feb 16 01:28:45 2011 From: bugcy013 at gmail.com (Ganesh Kumar) Date: Wed, 16 Feb 2011 11:58:45 +0530 Subject: Python GUI Tkinter Button arrangement Message-ID: Hi.. I am new to python , i have creating one application user agreement..using Tkinter, The Content of the agreement will reading one file...Agree button will click means enable next button. And activate script, Quit button for exit the program,, Dis agree means one warning message will show up.. all are working but one buttons are top of the screen. i want button in bottom of the frame plz. help me.. this my source code Source Code http://pastebin.com/Lm5teAtS Thanks in Advance -Ganesh. -- Did I learn something today? If not, I wasted it. From zhzhqiang at gmail.com Wed Feb 16 01:32:08 2011 From: zhzhqiang at gmail.com (fireinice) Date: Tue, 15 Feb 2011 22:32:08 -0800 (PST) Subject: Is this a bug of str.join? References: <289c9fbb-2163-4411-8fc4-9c912ab2b927@x13g2000vbe.googlegroups.com> Message-ID: <9f5dcca5-82ed-4ab1-829a-a1b339135fc6@f30g2000yqa.googlegroups.com> On Feb 16, 1:24?am, fireinice wrote: > Hi, all > I'm just working around to generate some fake file for parsing. and I > notice some weired thing happen. > ? ? time = str(random.randint(1000000000000000, 9999999999999999)) > ? ? s_id = str(random.randint(1000000000000000, 9999999999999999)) > ? ? p_id = str(random.randint(1000000000000000, 9999999999999999)) > ? ? a_id = str(random.randint(1000000000000000, 9999999999999999)) > ? ? s = "test" > ? ? a = [time, s_id, p_id, a_id, s] > ? ? print '\t'.join(a) > > the output is: > 3107903582321032 ? ? ? ?6101282916386924 ? ? ? ?719897196119318 1780339444980186test > > you can notice that there is no tab between a_id and s > if I switch a_id and p_id, it still happen, but if I delete one of > ids, the problem gone. > I tried this with python2.6 from debian source and python2.3 which I > compiled from source. the result are both the same. > What happened to str.join? > thanks I'm sorry, I found it should be the terminal width caused visual problem, please kindly ignore this post. From stefan_ml at behnel.de Wed Feb 16 01:34:27 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 16 Feb 2011 07:34:27 +0100 Subject: Is this a bug of str.join? In-Reply-To: <289c9fbb-2163-4411-8fc4-9c912ab2b927@x13g2000vbe.googlegroups.com> References: <289c9fbb-2163-4411-8fc4-9c912ab2b927@x13g2000vbe.googlegroups.com> Message-ID: fireinice, 16.02.2011 07:24: > Hi, all > I'm just working around to generate some fake file for parsing. and I > notice some weired thing happen. > time = str(random.randint(1000000000000000, 9999999999999999)) > s_id = str(random.randint(1000000000000000, 9999999999999999)) > p_id = str(random.randint(1000000000000000, 9999999999999999)) > a_id = str(random.randint(1000000000000000, 9999999999999999)) > s = "test" > a = [time, s_id, p_id, a_id, s] > print '\t'.join(a) > > the output is: > 3107903582321032 6101282916386924 719897196119318 1780339444980186test > > you can notice that there is no tab between a_id and s Likely just a presentation problem in your terminal. Try with a single space instead of tabs and see the difference. Stefan From stefan_ml at behnel.de Wed Feb 16 01:47:29 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 16 Feb 2011 07:47:29 +0100 Subject: Is this a bug of str.join? In-Reply-To: <9f5dcca5-82ed-4ab1-829a-a1b339135fc6@f30g2000yqa.googlegroups.com> References: <289c9fbb-2163-4411-8fc4-9c912ab2b927@x13g2000vbe.googlegroups.com> <9f5dcca5-82ed-4ab1-829a-a1b339135fc6@f30g2000yqa.googlegroups.com> Message-ID: fireinice, 16.02.2011 07:32: > On Feb 16, 1:24 am, fireinice wrote: >> Hi, all >> I'm just working around to generate some fake file for parsing. and I >> notice some weired thing happen. >> time = str(random.randint(1000000000000000, 9999999999999999)) >> s_id = str(random.randint(1000000000000000, 9999999999999999)) >> p_id = str(random.randint(1000000000000000, 9999999999999999)) >> a_id = str(random.randint(1000000000000000, 9999999999999999)) >> s = "test" >> a = [time, s_id, p_id, a_id, s] >> print '\t'.join(a) >> >> the output is: >> 3107903582321032 6101282916386924 719897196119318 1780339444980186test >> >> you can notice that there is no tab between a_id and s >> if I switch a_id and p_id, it still happen, but if I delete one of >> ids, the problem gone. >> I tried this with python2.6 from debian source and python2.3 which I >> compiled from source. the result are both the same. >> What happened to str.join? >> thanks > > I'm sorry, I found it should be the terminal width caused visual > problem, please kindly ignore this post. Well, there's always this that's worth remembering: http://www.catb.org/~esr/faqs/smart-questions.html#id478549 Stefan From spam at uce.gov Wed Feb 16 01:56:06 2011 From: spam at uce.gov (spam at uce.gov) Date: Tue, 15 Feb 2011 23:56:06 -0700 Subject: return an object of a different class In-Reply-To: <87bp2ch5xz.fsf@benfinney.id.au> References: <87bp2ch5xz.fsf@benfinney.id.au> Message-ID: >> I didn't explain my problem, chose a terrible example. This is more >> what I'm trying to do: Basically the subclass I want to use is based on some of the data I extract from a blob of data. If I use a function to extract the data before I create the objects, then I need to do a bunch of assignments afterwards. > > Unfortunately, it's still very contrived, and the names don't give any > suggestion as to what you're trying to achieve. Can you improve on that? > >> class ThingyTypeA: >> def __init__(self): >> # do some further extraction specific to type A >> further_extract() >> >> >> class ThingyTypeB: >> def __init__(self): >> # do some further extraction specific to type B >> further_extract() > > Perhaps you want those classes to inherit from your base class. Have you > done the Python tutorial? It covers inheritance and how to use it. Yes, I have done subclasing before, and yes ThingyTypeA and B should be subclassing Thingy -- Yves. http://www.SollerS.ca/ http://blog.zioup.org/ From ben+python at benfinney.id.au Wed Feb 16 02:22:36 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 16 Feb 2011 18:22:36 +1100 Subject: return an object of a different class References: <87bp2ch5xz.fsf@benfinney.id.au> Message-ID: <877hd0h29v.fsf@benfinney.id.au> spam at uce.gov writes: > > Perhaps you want those classes to inherit from your base class. Have > > you done the Python tutorial? It covers inheritance and how to use > > it. > > Yes, I have done subclasing before, and yes ThingyTypeA and B should > be subclassing Thingy Then your example still gives no indication why inheritance (allowing the common behaviour to be in the base class), along with a factory function (allowing the input data to determine which class gets instantiated), is not sufficient. -- \ ?When people believe that they have absolute knowledge, with no | `\ test in reality, this [the Auschwitz crematorium] is how they | _o__) behave.? ?Jacob Bronowski, _The Ascent of Man_, 1973 | Ben Finney From karim.liateni at free.fr Wed Feb 16 02:40:28 2011 From: karim.liateni at free.fr (Karim) Date: Wed, 16 Feb 2011 08:40:28 +0100 Subject: [Tutor] Accessing query results html frame :The solution In-Reply-To: <4D59230D.1030502@free.fr> References: <4D542AA0.5080801@free.fr> <4D54EA92.4030800@free.fr> <4D59230D.1030502@free.fr> Message-ID: <4D5B7F6C.5050605@free.fr> On 02/14/2011 01:41 PM, Karim wrote: > > Hello, > > As I get no response from the tutor python list, I am continuing to > investigate my problem. > > In fact the issue is that there are 2 forms in the interactive page > and my request does nothing > instead I get the interactive page not the submission I asked (query > results). The 2 forms are: > > 1. ENCTYPE="application/x-www-form-urlencoded" NAME="form1"> > 2. ENCTYPE="application/x-www-form-urlencoded" NAME="form9"> > > And the parameters for each are: > > 1) > > > > >   >   >   >   > ONCLICK="oncreate()">  > > > > > 2) > > > > > > And I recall my data of the progam below: > > data = { > 'init' : "", > 'LastForm': "SavedQuery", > 'prompted': "yes", > 'class': "Development", > 'personalQuery': "DKPV", > 'REMOTE_USER': username, > 'QS': " -p DKPVALIDATION_PLUGIN \(Class 'isequal' > "Development" \)", > 'use_field_defs':"false", > 'QueryName': "DKPV", > 'QueryType': "personal", > 'ACTION': "Query" > } > > So the question is how could I specify the correct FORM submission and > how could I chose the correct action because > there are several TYPE='submit' and I am only interested by this one > VALUE="Query"? > > Regards > Karim > > On 02/11/2011 08:51 AM, Karim wrote: >> >> Hello, >> >> In fact as found in the net: >> >> "The concept of browser frames is completely outside the scope of >> HTTP. However, browser frames are defined in HTML, and so is the >> target property on form elements: <form action="/somescript?x=y" >> method="POST" target="_top"> This will make the form submit to the >> _top frame, which means "use the full browser window" " >> >> That means that my post form: >> >> > ENCTYPE="application/x-www-form-urlencoded" TARGET="rightframe"> >> >> has a target property to make the submit to the 'rightframe'. >> >> Any ideas how I can modified the code (I think the request data or >> whatever) below to access without knowing the temporary html file >> name generically. >> >> Regards >> Karim >> >> On 02/10/2011 07:12 PM, Karim wrote: >>> >>> Hello All, >>> >>> I get from Steven an very useful link (void space) for http >>> authentication. I added some codes to be >>> able to POST FORM a query as I do it by clicking a query button to >>> get a list of bug Id on a server. >>> The problem is I get a html page which refers 2 frames. And I am >>> interesting in one particular frame >>> namely for example, >>> http://{server}:{port}/wt/tmp/results:karim.liateni.31_3917.html'.format(server=server, >>> port=port). >>> But this pages is created every times in a tmp directory each time >>> with a different name. >>> >>> 1) How can I get the name of this page because with python the page >>> resulting of my query is not mentionned (hidden like)? >>> Interactively there are 3 frames but only this one is of interest >>> for me. But no name of this page is visible in the main html page. >>> Is there a method to get all the nested frames locations? >>> >>> 2) I can see this page interactively when I click on a submit query >>> button. Do I need to add 'ACTION': "Query" >> in the query dictionnary to simulate a click for submission >>> (type="submit" button) ? >>> >>> 3) Interactively I see that cgi arg NextForm is empty so I let it >>> like that in my query and LastForm was set to "SavedQuery". I put the >>> same value in my python code. Is this ok? >>> >>> import urllib >>> import urllib2 >>> >>> server='dummy.com' >>> port='8081' >>> >>> username = 'karim.liateni' >>> password = 'dummy_pass' >>> >>> theurl = >>> 'http://{server}:{port}/ddts/ddts_main'.format(server=server, >>> port=port) >>> #theurl = >>> 'http://{server}:{port}:8081/wt/tmp/results:karim.liateni.31_3917.html'.format(server=server, >>> port=port) >>> >>> #MEMO: >>> #>> ENCTYPE="application/x-www-form-urlencoded" TARGET="rightframe"> >>> >>> data = { >>> 'NextForm': "", >>> 'LastForm': "SavedQuery", >>> 'prompted': "yes", >>> 'class': "Development", >>> 'personalQuery': "DKPV", >>> 'REMOTE_USER': username, >>> 'QS': " -p DKPVALIDATION_PLUGIN \(Class 'isequal' >>> "Development" \)", >>> 'use_field_defs':"false", >>> 'QueryName': "DKPV", >>> 'QueryType': "personal", >>> 'ACTION': "Query" >>> } >>> >>> query = urllib.urlencode(data) >>> request = urllib2.Request(theurl, query) >>> >>> passman = urllib2.HTTPPasswordMgrWithDefaultRealm() >>> passman.add_password(None, theurl, username, password) >>> authhandler = urllib2.HTTPBasicAuthHandler(passman) >>> >>> opener = urllib2.build_opener(authhandler) >>> urllib2.install_opener(opener) >>> >>> pagehandle = urllib2.urlopen(request) >>> print(pagehandle.read()) >>> _______________________________________________ >>> Tutor maillist - Tutor at python.org >>> To unsubscribe or change subscription options: >>> http://mail.python.org/mailman/listinfo/tutor >> >> _______________________________________________ >> Tutor maillist - Tutor at python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > > The solution to handle multiple post forms in a same web page and to submit a given one programmatically is to use this very must have module ClientForm from "http://wwwsearch.sourceforge.net/ClientForm" and maintained by John J.Lee Example from this module: response = urllib2.urlopen("http://wwwsearch.sourceforge.net/ClientForm/example.html") forms = ClientForm.ParseResponse(response, backwards_compat=False) form = forms[0] print form # set html widget value form["comments"] = "Thanks, Gisle" #Controls are html widgets (Listbox, checkbutton, combobox, etc ...) print "parmesan" in [item.name for item in form.find_control("cheeses").items if item.selected] # select item labelled "Mozzarella" in control with id "chz" as the same with a mouse-click: form.find_control(id="chz").get(label="Mozzarella").selected = True # submit the form returns a urllib2.Request object new_request = form.click() new_response = urllib2.urlopen(new_request) This is a very handy and easy module! For whom it mays concern. Regards Karim -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric.brunel at pragmadev.nospam.com Wed Feb 16 03:48:57 2011 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Wed, 16 Feb 2011 09:48:57 +0100 Subject: Another related OO Python ? References: Message-ID: In article , Doug Epling wrote: > hey, does anyone find the UML useful during Python development of larger > projects? Well, UML being very Java/C++ oriented, I found out that Python idioms were really difficult to represent in the diagrams. So I'm using it to a very small extent and for documentation only, just to give an idea about how classes are organized. For the rest, and IMHO, it's really too impractical to be of any use. From eric.brunel at pragmadev.nospam.com Wed Feb 16 03:55:28 2011 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Wed, 16 Feb 2011 09:55:28 +0100 Subject: How does IDLE do it? References: Message-ID: In article , "Richard D. Moores" wrote: > I recently wrote some code that prints information about the 'jukugo' > used in Japanese newspaper articles. A jukugo is a Japanese word > written with at least 2 kanji. An example of a 2-kanji jukugo is ?????? > (kiki -- crisis). I found that I could not use my usual IDE to render > the Japanese correctly in either the code or the output. But IDLE > (version 3.1.2; Windows Vista) does a beautiful job! See screen shots > > and > . > (The whole script plus output is at > .) > > I'd like to know how the IDLE developers did this. How can IDLE not > have a problem with Japanese using Courier New, Calibri, even Fences > or Windings! (For Wingdings, see > .) IDLE doesn't do anything, tk does. When a character is not available in a given font, tk looks up for one containing it by itself and uses it automatically. > Thanks, > > Dick Moores From karim.liateni at free.fr Wed Feb 16 04:04:46 2011 From: karim.liateni at free.fr (Karim) Date: Wed, 16 Feb 2011 10:04:46 +0100 Subject: return an object of a different class In-Reply-To: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> Message-ID: <4D5B932E.9000206@free.fr> On 02/16/2011 06:05 AM, Richard Thomas wrote: > On Feb 16, 2:23 am, s... at uce.gov wrote: >> How can I do something like this in python: >> >> #!/usr/bin/python3.1 >> >> class MyNumbers: >> def __init__(self, n): >> self.original_value = n >> if n<= 100: >> self = SmallNumers(self) >> else: >> self = BigNumbers(self) >> >> class SmallNumbers: >> def __init__(self, n): >> self.size = 'small' >> >> class BigNumbers: >> def __init__(self, n): >> self.size = 'big' >> >> t = MyNumbers(200) >> >> When I do type(t) it says MyNumbers, while I'd want it to be BigNumbers, >> because BigNumbers and SmallNumbers will have different methods etc... >> >> Do I need to use metaclasses? >> >> Thanks. >> -- >> Yves. http://www.SollerS.ca/ >> http://blog.zioup.org/ > If you don't want to use a factory function I believe you can do this: > > class MyNumber(object): > def __new__(cls, n): > if n<= 100: > cls = SmallNumbers > else: > cls = BigNumbers > return object.__new__(cls, n) > ... > > Chard. Very beautiful code great alternative to factory method! To memorize this pythonic way. Regards Karim From arndt.roger at addcom.de Wed Feb 16 04:04:52 2011 From: arndt.roger at addcom.de (Arndt Roger Schneider) Date: Wed, 16 Feb 2011 10:04:52 +0100 Subject: Displaying SVG in tkinter using cairo and rsvg References: Message-ID: Martin P. Hellwig schrieb: > Hi all, > > Information on using tkinter for displaying an svg image seems a bit low > spread on the Internet. I recently played around with pygame and svg and > realized, hold on this can be done with tk too. So I thought I post a > little example for future generations :-) (and also have stored at > http://dcuktec.googlecode.com/hg/source/examples/cairo_rsvg_tkinter.py). > > So here it is if you are interested: [snip] raster images from SVG: There are multiple methods to convert a scalable vector graphic into a bitmap. In addition to cairo, librsvg and rsvg imageMagick contains a vector graphic format similar to svg--gradients and transparency are problematic for this approach, but its a while since I had looked into it... My product Jeszra imports svg into Tk(using tkpath http://jeszra.sourceforge.net/jeszra/Jeszra_TechnicalNotes.html#d0e10279 ), preserving it as a vector graphics. There are, of course, limitations to what can be preserved in Tk: http://jeszra.sourceforge.net/jeszra/SVG_Import.html The other way is much simpler to convert a Tk graphics into svg, which is also implemented in Jeszra. All svg graphics on http://jeszra.sourceforge.net and http://gestaltitems.sourceforge.net are generated by Jeszra from Tk (there are some hundred graphics)... The generator API is open and a draft documentation is online at: http://jeszra.sourceforge.net/api/ch01s04.html http://jeszra.sourceforge.net/api/index.html Jeszra API Concerning svg: http://jeszra.sourceforge.net/api/ch04.html http://jeszra.sourceforge.net/api/ch05.html http://jeszra.sourceforge.net/api/ch06.html http://jeszra.sourceforge.net/api/ch07.html http://jeszra.sourceforge.net/api/ch08.html Here is an overview about Jeszra, SVG and Tk: http://jeszra.sourceforge.net/api/pictures/overview.svg The svg on those page gets on-demand converted into flash, for the internet explorer. Is there anyting else You want to know about svg? -roger From nospam at nospam.com Wed Feb 16 04:17:56 2011 From: nospam at nospam.com (Gilles Ganault) Date: Wed, 16 Feb 2011 10:17:56 +0100 Subject: [newbie/2.5.1.1] Computing value of a word? Message-ID: Hello, For a game, I need to go through a wordlist, and for each word, compute its value, ie. a=1, b=2, etc. So for instance, NewYork = 14 + 5 + 23 + 25 + 15 + 18 + 11 = 111. Before I write the obvious While loop to go through each line in the input text file, I was wondering if Python didn't already have some function to perform this type of computation. Thank you. From clp2 at rebertia.com Wed Feb 16 04:27:06 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 16 Feb 2011 01:27:06 -0800 Subject: [newbie/2.5.1.1] Computing value of a word? In-Reply-To: References: Message-ID: On Wed, Feb 16, 2011 at 1:17 AM, Gilles Ganault wrote: > Hello, > > For a game, I need to go through a wordlist, and for each word, > compute its value, ie. a=1, b=2, etc. > > So for instance, NewYork = 14 + 5 + 23 + 25 + 15 + 18 + 11 = 111. > > Before I write the obvious While loop to go through each line in the > input text file, I was wondering if Python didn't already have some > function to perform this type of computation. A = ord('a') - 1 for line in your_file: word = line.strip().lower() score = sum(ord(letter)-A for letter in word) Cheers, Chris -- http://blog.rebertia.com From dmitrey.kroshko at scipy.org Wed Feb 16 04:37:25 2011 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Wed, 16 Feb 2011 01:37:25 -0800 (PST) Subject: [ANN] New package: SpaceFuncs (2D, 3D, ND geometric modeling, optimization, solving) Message-ID: <342667fb-fad0-4cfd-8bea-05bd8c1b6992@l22g2000pre.googlegroups.com> Hi all, I'm glad to inform you about new, 4th OpenOpt Suite module: SpaceFuncs - a tool for 2D, 3D, N-dimensional geometric modeling with possibilities of parametrized calculations, numerical optimization and solving systems of geometrical equations. For details see its home page http://openopt.org/SpaceFuncs and documentation http://openopt.org/SpaceFuncsDoc The module is written in Python + NumPy, requires FuncDesigner (and OpenOpt, DerApproximator for some operations). It has completely free license: BSD. Also, you can try it online via our Sage-server http://sage.openopt.org/welcome Regards, Dmitrey. From martin.hellwig at dcuktec.org Wed Feb 16 04:49:10 2011 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 16 Feb 2011 09:49:10 +0000 Subject: Displaying SVG in tkinter using cairo and rsvg In-Reply-To: References: Message-ID: On 02/16/11 09:04, Arndt Roger Schneider wrote: > raster images from SVG: > There are multiple methods to convert a scalable vector graphic > into a bitmap. > In addition to cairo, librsvg and rsvg imageMagick contains a > vector graphic format similar to svg--gradients and transparency > are problematic for this approach, but its a while since I had > looked into it... > > My product Jeszra imports svg into Tk(using tkpath > http://jeszra.sourceforge.net/jeszra/Jeszra_TechnicalNotes.html#d0e10279 > ), preserving it as a vector graphics. > There are, of course, limitations to what can be preserved in Tk: tkpath does not seem to come standard with Python's tk version when I looked into it a couple of years ago, but maybe it has now? > Is there anyting else You want to know about svg? > No not really :-), I just wanted to display a SVG in tkinter with the minimal amount of external dependencies, since I have achieved that I thought I share my experience, so that the next time someone google tkinter and display svg it will return something that (well at least of the time of this writing) worked. Thanks for the info though. -- mph From arndt.roger at addcom.de Wed Feb 16 06:00:30 2011 From: arndt.roger at addcom.de (Arndt Roger Schneider) Date: Wed, 16 Feb 2011 12:00:30 +0100 Subject: Displaying SVG in tkinter using cairo and rsvg References: Message-ID: Martin P. Hellwig schrieb: > On 02/16/11 09:04, Arndt Roger Schneider wrote: [snip] > tkpath does not seem to come standard with Python's tk version when I > looked into it a couple of years ago, but maybe it has now? > tk canvas and tkpath share the same interface, the first tkpath was a plugin into the tk canvas. A tkinter wrapper class will be a simple subclass of tk canvas introducing the new item types: path, ppolygone, polyline, circle, elipsis, pimage, prect, ptext, group and for tkpath 0.3 three additional messages for: style, gradient and distance, that's all ~50 lines of code. >> Is there anyting else You want to know about svg? >> > > No not really :-), I just wanted to display a SVG in tkinter with the > minimal amount of external dependencies, since I have achieved that I > thought I share my experience, so that the next time someone google > tkinter and display svg it will return something that (well at least of > the time of this writing) worked. > Well CAIRO is sort of a shifting target... --currently I am stuck with PPC and new CAIRO versions cannot longer being built on it anymore :-(-- CAIRO can be real pain on non-X11-linux platforms. ImageMagick is simpler than CAIRO cross-platform wise. -roger From eaglebalti at gmail.com Wed Feb 16 07:39:33 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Wed, 16 Feb 2011 04:39:33 -0800 (PST) Subject: hot hot and hot indian actresses Message-ID: Hello friends how r u all? what about indian hot girls? just visit www.hotpictures-glaxi.blogspot.com www.onlinetv-glaxi.blogspot.com www.onlineradio-glaxi.blogspot.com From dpalao.python at gmail.com Wed Feb 16 08:18:27 2011 From: dpalao.python at gmail.com (DPalao) Date: Wed, 16 Feb 2011 14:18:27 +0100 Subject: 70% [* SPAM *] shelve trying to import bsddb Message-ID: <6247_1297862314_p1GDIO81016242_201102161418.27474.dpalao.python@gmail.com> Dear all, I'm trying to use shelve to store some data, but sheve itself tries to import bsddb, which results in: > File "/usr/lib64/python2.6/shelve.py", line 239, in open > return DbfilenameShelf(filename, flag, protocol, writeback) > File "/usr/lib64/python2.6/shelve.py", line 223, in __init__ > Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback) > File "/usr/lib64/python2.6/anydbm.py", line 82, in open > mod = __import__(result) > File "/usr/lib64/python2.6/dbhash.py", line 8, in > import bsddb > ImportError: No module named bsddb I know that the new bsddb3 should be used, so what can I do? TIA, D From steve+comp.lang.python at pearwood.info Wed Feb 16 08:20:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Feb 2011 13:20:39 GMT Subject: return an object of a different class References: Message-ID: <4d5bcf27$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 19:23:39 -0700, spam wrote: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > def __init__(self, n): > self.original_value = n > if n <= 100: > self = SmallNumers(self) > else: > self = BigNumbers(self) (1) self is just a local variable, it isn't privileged in any way. Assigning to the name "self" doesn't magically change the instance, so that can't work. (2) By the time the __init__ method is called, the instance has been created. __init__ is the initializer, you need the constructor. Something like this: # Untested. class MyNumbers: def __new__(cls, n): if n <= 100: instance = SmallNumbers(n) else: instance = BigNumbers(n) return instance -- Steven From steve+comp.lang.python at pearwood.info Wed Feb 16 08:24:18 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Feb 2011 13:24:18 GMT Subject: return an object of a different class References: Message-ID: <4d5bd002$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 22:17:13 -0700, spam wrote: > I didn't explain my problem, chose a terrible example. This is more what > I'm trying to do: [snip "thingy" class] No, your first example was better. This one is terrible -- it's so generic it's meaningless. In any case, you don't explain why it has to be a class, rather than a factory function. -- Steven From steve+comp.lang.python at pearwood.info Wed Feb 16 08:25:36 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Feb 2011 13:25:36 GMT Subject: interleave string References: Message-ID: <4d5bd050$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 19:39:30 -0800, alex23 wrote: > Andrea Crotti wrote: >> At the moment I have this ugly inliner >> ? ? ? ? interleaved = ':'.join(orig[x:x+2] for x in range(0, >> ? ? ? ? len(orig), 2)) > > I actually prefer this over every other solution to date. Agreed. To me, it's the simplest, least contrived way to solve the problem. -- Steven From rbotting at csusb.edu Wed Feb 16 08:33:22 2011 From: rbotting at csusb.edu (RJB) Date: Wed, 16 Feb 2011 05:33:22 -0800 (PST) Subject: Another related OO Python ? References: Message-ID: <6849fd3f-5116-4b35-b274-dc76ae39f777@a11g2000pro.googlegroups.com> On Feb 16, 12:48?am, Eric Brunel wrote: > In article , > ?Doug Epling wrote: > > > hey, does anyone find the UML useful during Python development of larger > > projects? > > Well, UML being very Java/C++ oriented, I found out that Python idioms > were really difficult to represent in the diagrams. So I'm using it to a > very small extent and for documentation only, just to give an idea about > how classes are organized. For the rest, and IMHO, it's really too > impractical to be of any use. Which of the 13 diagrams have tried and rejected?-) From peter.mosley at talk21.com Wed Feb 16 08:33:26 2011 From: peter.mosley at talk21.com (peter) Date: Wed, 16 Feb 2011 05:33:26 -0800 (PST) Subject: Archiving Modules Message-ID: <9a340d80-ddfd-4985-8b2c-1e4a14e953a9@w21g2000yqm.googlegroups.com> I am writing a small Tkinter utility to control archive files in multiple formats (mainly for my own amusement and education). Basically it presents the user with two adjacent listboxes, one with the contents of the target directory and one with the contents of the archive. By clicking buttons labelled '<' and '>' the user can copy files to and from the archive. The actual archiving functionality derives from the modules zipfile and tarfile. It all seems to be working fine, but I have two residual queries. Firstly for the sake of completeness I would like to include .rar archives, but there doesn't seem to be an equivalent rarfile module. I use both Windows and Linux on various machines, so need a cross platform solution which does not depend on external modules. The only one I have found is at http://pypi.python.org/pypi/rarfile/1.0, but it seems this does rely on an external module. Is there anything out there? Secondly, I found that when extracting zip files, the date stamps were all reset to the date/time of extraction, whereas for tar files they retained their original values. This second behaviour seems more logical, and I have simulated it for the zipfiles by using zipfile.getinfo to read the original date then os.utime to rewrite it. It seems rather messy - have I missed something simple like a flag setting within zipfile? Peter From steve+comp.lang.python at pearwood.info Wed Feb 16 08:35:24 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Feb 2011 13:35:24 GMT Subject: Map vs. List Comprehensions (was "lint warnings") References: Message-ID: <4d5bd29c$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Feb 2011 18:55:50 -0500, Gerald Britton wrote: > So, what's the feeling out there? Go with map and the operators or > stick with the list comps? Stick to whatever feels and reads better at the time. Unless you have profiled your code, and determined that the map or list comp was the bottleneck, who cares if you save half a nanosecond per iteration? map clearly loses badly in the old-time idiom: map(lambda x: x+1, seq) or similar. That's the only time I'd just flat out say, avoid map in favour of a list comprehension. Otherwise, the performance difference is likely to be trivial, as is the difference in length of code. Use whichever you like. I personally appreciate the ability to treat map as a primitive ("map this function over this data") rather than caring about the mechanics of iteration ("iterate over data, applying this function to each element in turn"), so I often use map. But I use list comps even more often. -- Steven From dpalao.python at gmail.com Wed Feb 16 08:59:25 2011 From: dpalao.python at gmail.com (DPalao) Date: Wed, 16 Feb 2011 14:59:25 +0100 Subject: 70% [* SPAM *] Re: shelve trying to import bsddb In-Reply-To: <6247_1297862314_p1GDIO81016242_201102161418.27474.dpalao.python@gmail.com> References: <6247_1297862314_p1GDIO81016242_201102161418.27474.dpalao.python@gmail.com> Message-ID: <6247_1297864772_p1GDxLNe003096_201102161459.25498.dpalao.python@gmail.com> El Wednesday February 16 2011, DPalao escribi?: > Dear all, > I'm trying to use shelve to store some data, but sheve itself tries to > import > > bsddb, which results in: > > File "/usr/lib64/python2.6/shelve.py", line 239, in open > > > > return DbfilenameShelf(filename, flag, protocol, writeback) > > > > File "/usr/lib64/python2.6/shelve.py", line 223, in __init__ > > > > Shelf.__init__(self, anydbm.open(filename, flag), protocol, > > writeback) > > > > File "/usr/lib64/python2.6/anydbm.py", line 82, in open > > > > mod = __import__(result) > > > > File "/usr/lib64/python2.6/dbhash.py", line 8, in > > > > import bsddb > > > > ImportError: No module named bsddb > > I know that the new bsddb3 should be used, so what can I do? > TIA, > > D I solved the issue. I just compiled python (btw, I'm using 2.6.6) with support for "berkdb", which apparently disappeared in a recent update (I'm using gentoo). From eric.brunel at pragmadev.nospam.com Wed Feb 16 09:21:03 2011 From: eric.brunel at pragmadev.nospam.com (Eric Brunel) Date: Wed, 16 Feb 2011 15:21:03 +0100 Subject: Another related OO Python ? References: <6849fd3f-5116-4b35-b274-dc76ae39f777@a11g2000pro.googlegroups.com> Message-ID: In article <6849fd3f-5116-4b35-b274-dc76ae39f777 at a11g2000pro.googlegroups.com>, RJB wrote: > On Feb 16, 12:48?am, Eric Brunel > wrote: > > In article , > > ?Doug Epling wrote: > > > > > hey, does anyone find the UML useful during Python development of larger > > > projects? > > > > Well, UML being very Java/C++ oriented, I found out that Python idioms > > were really difficult to represent in the diagrams. So I'm using it to a > > very small extent and for documentation only, just to give an idea about > > how classes are organized. For the rest, and IMHO, it's really too > > impractical to be of any use. > > Which of the 13 diagrams have tried and rejected?-) Diagrams that aren't too bound to the language like e.g the deployment diagram can still be used, of course. I was mainly talking about the class diagram, which is still the central point of a model. But I even found sequence diagrams quite hard to write for Python, unless they are very simplistic ones. From benhoyt at gmail.com Wed Feb 16 09:30:52 2011 From: benhoyt at gmail.com (benhoyt) Date: Wed, 16 Feb 2011 06:30:52 -0800 (PST) Subject: logging module -- better timestamp accuracy on Windows In-Reply-To: Message-ID: <991dc185-f2be-4e61-a669-19adc713ce8b@glegroupsg2000goo.googlegroups.com> > A simpler solution would be to caclulate the time it takes to the handle > the request using time.clock() and include it in the log message. > Something like: Thanks, Ross. Actually, we are doing exactly that already -- it's how we noticed the timestamp issue in the first place. However, that doesn't fix it when we have multiple logged events that we want to calculate time deltas between, such as: 2011-02-15T10:11:12.123 Starting request 2011-02-15T10:11:12.123 Doing stuff 2011-02-15T10:11:12.123 Filtering stuff 2011-02-15T10:11:12.123 Rendering template 2011-02-15T10:11:12.123 Request complete, took 0.56 ms It seems to me that the logging module should use a millisecond-accurate timestamp (time.clock) on Windows, just like the "timeit" module does. -Ben From vinay_sajip at yahoo.co.uk Wed Feb 16 10:32:39 2011 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 16 Feb 2011 07:32:39 -0800 (PST) Subject: logging module -- better timestamp accuracy on Windows References: <991dc185-f2be-4e61-a669-19adc713ce8b@glegroupsg2000goo.googlegroups.com> Message-ID: <8734a0a8-136f-4781-9317-51f0389c2407@o13g2000yql.googlegroups.com> On Feb 16, 2:30?pm, benhoyt wrote: > It seems to me that the logging module should use a millisecond-accurate timestamp (time.clock) on Windows, > just like the "timeit" module does. It's not an unreasonable request, though I don't think logging should be used to time things accurately. I'm also not sure about the exact form the solution might take. For example, are you assuming that your clock() call in logging is the very first call made? If it's not, then wouldn't this throw your calculations off? Or have I misunderstood how clock() works? Also, IIUC the resolution of clock() is < 1 usec, but as logging only prints to the nearest msec, won't you lose much of the benefit of the increased resolution? In your above example your request processing took 0.56 msec, so at best you would see a 1 msec difference between start and finish times in the log - that doesn't seem like it would be good enough; plus, if the process took less than 0.5 msec, then you might see identical start and finish times in the log. Or are you saying that the times should be formatted/printed to microsecond accuracy? Of course 3.2 is at rc3, and branches for 2.x are closed except for security fixes, so I'm not sure when this could go in to an official release ... Thanks & regards, Vinay Sajip From sturlamolden at yahoo.no Wed Feb 16 10:34:20 2011 From: sturlamolden at yahoo.no (sturlamolden) Date: Wed, 16 Feb 2011 07:34:20 -0800 (PST) Subject: logging module -- better timestamp accuracy on Windows References: <991dc185-f2be-4e61-a669-19adc713ce8b@glegroupsg2000goo.googlegroups.com> Message-ID: <6fdaebe9-3be4-4163-a769-0e2e018c6c37@y35g2000prc.googlegroups.com> On 16 Feb, 15:30, benhoyt wrote: > It seems to me that the logging module should use a millisecond-accurate timestamp (time.clock) on Windows, just like the "timeit" module does. AFAIK, the Windows performance counter has long-term accuracy issues, so neither is perfect. Preferably we should have a timer with the long- term accuracy of time.time and the short-term accuracy of time.clock. Sturla From tjreedy at udel.edu Wed Feb 16 12:01:44 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Feb 2011 12:01:44 -0500 Subject: Is this a bug of str.join? In-Reply-To: <9f5dcca5-82ed-4ab1-829a-a1b339135fc6@f30g2000yqa.googlegroups.com> References: <289c9fbb-2163-4411-8fc4-9c912ab2b927@x13g2000vbe.googlegroups.com> <9f5dcca5-82ed-4ab1-829a-a1b339135fc6@f30g2000yqa.googlegroups.com> Message-ID: On 2/16/2011 1:32 AM, fireinice wrote: > On Feb 16, 1:24 am, fireinice wrote: >> Hi, all >> I'm just working around to generate some fake file for parsing. and I >> notice some weired thing happen. >> time = str(random.randint(1000000000000000, 9999999999999999)) >> s_id = str(random.randint(1000000000000000, 9999999999999999)) >> p_id = str(random.randint(1000000000000000, 9999999999999999)) >> a_id = str(random.randint(1000000000000000, 9999999999999999)) >> s = "test" >> a = [time, s_id, p_id, a_id, s] >> print '\t'.join(a) >> >> the output is: >> 3107903582321032 6101282916386924 719897196119318 1780339444980186test >> >> you can notice that there is no tab between a_id and s >> if I switch a_id and p_id, it still happen, but if I delete one of >> ids, the problem gone. >> I tried this with python2.6 from debian source and python2.3 which I >> compiled from source. the result are both the same. >> What happened to str.join? >> thanks > > I'm sorry, I found it should be the terminal width caused visual > problem, please kindly ignore this post. For future reference, the way to get more info about what is really in a string is to print its repr(), or even its list() version. Len() is also helpful. On Windows, both the Command Prompt window and IDLE refuse to expand tabs, so >>> s='\t'.join(('a','b','c')) >>> str(s) 'a\tb\tc' >>> repr(s) "'a\\tb\\tc'" >>> len(s) 5 >>> list(s) ['a', '\t', 'b', '\t', 'c'] -- Terry Jan Reedy From brian.curtin at gmail.com Wed Feb 16 12:02:45 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Wed, 16 Feb 2011 11:02:45 -0600 Subject: logging module -- better timestamp accuracy on Windows In-Reply-To: <6fdaebe9-3be4-4163-a769-0e2e018c6c37@y35g2000prc.googlegroups.com> References: <991dc185-f2be-4e61-a669-19adc713ce8b@glegroupsg2000goo.googlegroups.com> <6fdaebe9-3be4-4163-a769-0e2e018c6c37@y35g2000prc.googlegroups.com> Message-ID: On Wed, Feb 16, 2011 at 09:34, sturlamolden wrote: > On 16 Feb, 15:30, benhoyt wrote: > > > It seems to me that the logging module should use a millisecond-accurate > timestamp (time.clock) on Windows, just like the "timeit" module does. > > AFAIK, the Windows performance counter has long-term accuracy issues, > so neither is perfect. Preferably we should have a timer with the long- > term accuracy of time.time and the short-term accuracy of time.clock. > > Sturla I just uploaded a timer extension I wrote a while back which tries to solve some of this: http://pypi.python.org/pypi/timer (supports Python 2 and 3) It takes an idea from MSDN Magazine about creating reliable and accurate high resolution timers and converts it into somewhat of a threading.Timer replacement. It accepts a duration in microseconds and can be stopped, giving you the current elapsed microseconds. I should add an infinite argument so it can be used more like a stopwatch, rather than requiring a duration. It appears to be fairly accurate so far, but I wouldn't count lives on it just yet. -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Feb 16 12:03:58 2011 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 16 Feb 2011 13:03:58 -0400 Subject: OT: Need Interactivity With the Browser Message-ID: Hi; I would like to build a component where the user can go to a page, say he'd like to upload so many ("x") number of photos, click a button and without leaving the page have three sets of upload widgets pop up. I think this is done with Json; however, I can't find much info or tutorials on the same that help me know if Json is my tool. (After spending a half hour studying it online I'm still at a loss as to how it helps or what id does, just that it's somewhat similar to XML) And I cannot find a discussion list on the subject, either. Please advise. TIA, Beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Feb 16 12:16:30 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Feb 2011 12:16:30 -0500 Subject: unicode shutil.copy() changes a file name during copy? In-Reply-To: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> References: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> Message-ID: On 2/15/2011 11:50 PM, dave wrote: > i'm on windows, using active python 2.7.1 > > i've written a script to copy a folder of files to dest folder.. > > one if the files in this folder has the section symbol (?, '\x15') as > part of the file name > shutil.copy(src_file, dst_file) "can't find the file specified" when > it does the os.chmod() part, can't find dest file, > cuz the file got copied with "_" in place of the section symbol. > gar. What happens if you try this with 3.2? -- Terry Jan Reedy From nickname at banelli.biz.invalid Wed Feb 16 12:26:40 2011 From: nickname at banelli.biz.invalid (Bubba) Date: 16 Feb 2011 17:26:40 GMT Subject: How to handle sockets - easily? References: <878vxo9jeo.fsf@araminta.anjou.terraraq.org.uk> Message-ID: Richard Kettlewell's log on stardate 10 vlj 2011 > Rewrites can help but they can also go badly wrong. Rewriting into a > language you don't yet know seems especially likely to fall into the > latter category! Indeed. However, it seems to be quite "doable", as it took me from 0 knowledge of Python to come up with a solution that does only part of the thing (it's missing CRC check for GPS data and NMEA checksum, user control for changing device setup on the fly via web and few more details). Here's the code (ATTN: may wrap): #! /usr/bin/env python import asyncore import socket import string import MySQLdb import sys class Handler(asyncore.dispatcher_with_send): def handle_read(self): data = self.recv(128) #payload size data = string.lstrip(data,"\n") #sometimes a 0xOA stays data_len = len (data) #get payload length trackerID_hex = data[4:11] #tracker ID trackerID = "" #create empty string for i in trackerID_hex: trackerID += str('%02X'%ord(i)) #convert hex integer to string and append to trackerID trackerID = string.rstrip(trackerID,"F") #remove stuffed F's from tracker ID checksum = "" checksum_hex = data[data_len-4:data_len-1] #second part of command payload, checksum for i in checksum_hex: checksum += str('%02X'%ord(i)) #convert hex integer to string and append to trackerID GPSdata = data[13:data_len-4] #GPRMC - hhmmss.dd,S,xxmm.dddd,,yyymm.dddd,,s.s,h.h,ddmmyy l = list() l = string.split(GPSdata, ",") n = len(l) if n > 1: #hack! devices can mess the output, so just discard the data and go to another sample GPStime = l[0] GPStime = GPStime[0:2] + ":" + GPStime[2:4] + ":" + GPStime[4:6] GPSstatus = l[1] GPSlatitude = l[2] GPSlatitude = float(GPSlatitude[0:2]) + float(GPSlatitude[2:10]) / 60 GPSNS = l[3] GPSlongitude = l[4] GPSlongitude = float(GPSlongitude[0:3]) + float(GPSlongitude[3:11]) / 60 GPSEW = l[5] try: GPSspeed = float(l[6]) except ValueError: GPSspeed = 0 GPSspeed *= 1.852 try: GPSheading = float(l[7]) except ValueError: GPSheading = 0 GPSdate = l[8] GPSdate = "20" + GPSdate[4:6] + "-" + GPSdate[2:4] + "-" + GPSdate[0:2] try: conn = MySQLdb.connect (host = "localhost", user = "", passwd = "", db = "") #:p except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) sys.exit (1) cursor = conn.cursor() query = "INSERT INTO data (trackerID, GPStime, GPSstatus, GPSlatitude, GPSNS, GPSlongitude, GPSEW, GPSspeed, GPSheading, GPSdate) VALUES ('" + trackerID + "', '" + GPStime + "', '" + GPSstatus + "', '" + str(GPSlatitude) + "', '" + GPSNS + "', '" + str(GPSlongitude) + "', '" + GPSEW + "', '" + str(GPSspeed) + "', '" + str(GPSheading) + "', '" + GPSdate + "')" cursor.execute (query) cursor.close () conn.commit() conn.close () class Server(asyncore.dispatcher): def __init__(self, host, port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((host, port)) self.listen(5) def handle_accept(self): pair = self.accept() if pair is None: pass else: sock, addr = pair print 'Incoming connection from %s' % repr(addr) handler = Handler(sock) server = Server('', 2020) asyncore.loop() C code did not parse data, but rather put the whole payload to SQL database, which would be parsed afterwards. This code takes almost twice LOC less that C code. I do, however, have some more questions (thus crosspost to comp.lang.python) - how many connections can this server handle without a problem? I'm using Asyncore module, as it can be seen. Is it necessary, due to the fact that it should serve more than thousand devices that send data every 10 seconds, to do threading (I believe that is already done with Asyncore for sockets, but what about SQL?) Any other general code suggestions (since this is the first time I write anything in Python)? TIA! -- "If you lie to the compiler, it will get its revenge." Henry Spencer 2.718281828459045235360287471352662497757247093699959574966967627.com From benhoyt at gmail.com Wed Feb 16 13:23:39 2011 From: benhoyt at gmail.com (benhoyt) Date: Wed, 16 Feb 2011 10:23:39 -0800 (PST) Subject: logging module -- better timestamp accuracy on Windows In-Reply-To: <6fdaebe9-3be4-4163-a769-0e2e018c6c37@y35g2000prc.googlegroups.com> Message-ID: > AFAIK, the Windows performance counter has long-term accuracy issues, > so neither is perfect. Preferably we should have a timer with the long- > term accuracy of time.time and the short-term accuracy of time.clock. Thanks for the tip -- yes, I hadn't thought about that, but you're right, QueryPerformanceCounter (and hence time.clock) veers away from the system time, and it's non-trivial to fix. See also: http://msdn.microsoft.com/en-us/magazine/cc163996.aspx http://social.msdn.microsoft.com/forums/en-US/windowsgeneraldevelopmentissues/thread/a8b2c286-1133-4827-97be-61e27687ff5d -Ben From anbaricforce at gmail.com Wed Feb 16 13:28:43 2011 From: anbaricforce at gmail.com (dave) Date: Wed, 16 Feb 2011 10:28:43 -0800 (PST) Subject: unicode shutil.copy() changes a file name during copy? References: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> Message-ID: <412db27a-3e57-4344-9582-c5f954dbf4ce@f36g2000pri.googlegroups.com> i don't see an "active python 3.2" i see "3.1" and "Many 3rd-party modules and extensions that you may depend upon may not yet be available for Python 3. As a result you may want to continue to use Python 2 for the time being". and i depend on some 3rd party modules. no i really think it's something like: string = string.decode('latin_1').endocde('utf8') or something. i just don't know what's expected. i've tried various flavors but can't figure it out. it's very easy to test it yourself, just make a file with the section symbol in it, then try to copy it with python 2.7.1 From benhoyt at gmail.com Wed Feb 16 13:29:00 2011 From: benhoyt at gmail.com (benhoyt) Date: Wed, 16 Feb 2011 10:29:00 -0800 (PST) Subject: logging module -- better timestamp accuracy on Windows In-Reply-To: <8734a0a8-136f-4781-9317-51f0389c2407@o13g2000yql.googlegroups.com> Message-ID: > For example, are you assuming that your clock() call in logging is > the very first call made? Yes, we were making that assumption (the time.clock() call in the import of our log module), which was true in our code, but I can see where it's not a good thing to assume generally. > Also, IIUC the resolution of clock() is < 1 usec, but > as logging only prints to the nearest msec, won't you lose much of the > benefit of the increased resolution? ... > Or are you saying that the times should be formatted/printed to > microsecond accuracy? No, millisecond is fine. The 0.56ms example I gave in response to Rick was a really bad example -- It's more like when it's 5.6 ms that it's a problem for us, because the request time is saying 5.6ms, but the log timestamps within and at the end of that request are identical. Anyway, as sturlamolden mentioned, time.clock() has long-term accuracy issues (gets out of sync with time.time()), so that's not really a good solution. So the way it is is non-ideal, but that's more a fact of life due to the Windows time functions than anything else. It's not trivial to solve, so we're going to leave it for now, and just use time.clock() to time individual pieces of code when we need more accuracy... -Ben From snorble at hotmail.com Wed Feb 16 13:35:28 2011 From: snorble at hotmail.com (snorble) Date: Wed, 16 Feb 2011 10:35:28 -0800 (PST) Subject: How to use Python well? Message-ID: I use Python a lot, but not well. I usually start by writing a small script, no classes or modules. Then I add more content to the loops, and repeat. It's a bit of a trial and error learning phase, making sure I'm using the third party modules correctly, and so on. I end up with a working script, but by the end it looks messy, unorganized, and feels hacked together. I feel like in order to reuse it or expand it in the future, I need to take what I learned and rewrite it from scratch. If I peeked over a Python expert's shoulder while they developed something new, how would their habits differ? Do they start with classes from the start? I guess I'm looking for something similar to "Large Scale C++ Software Design" for Python. Or even just a walkthrough of someone competent writing something from scratch. I'm not necessarily looking for a finished product that is well written. I'm more interested in, "I have an idea for a script/program, and here is how I get from point A to point B." Or maybe I'm looking for is best practices for how to organize the structure of a Python program. I love Python and I just want to be able to use it well. From william at wilbur.25thandClement.com Wed Feb 16 13:59:27 2011 From: william at wilbur.25thandClement.com (William Ahern) Date: Wed, 16 Feb 2011 10:59:27 -0800 Subject: How to handle sockets - easily? References: <878vxo9jeo.fsf@araminta.anjou.terraraq.org.uk> Message-ID: Bubba wrote: > import asyncore > import socket > import string > import MySQLdb > import sys > def __init__(self, host, port): > asyncore.dispatcher.__init__(self) > self.create_socket(socket.AF_INET, socket.SOCK_STREAM) > self.set_reuse_addr() > self.bind((host, port)) > self.listen(5) > > def handle_accept(self): > pair = self.accept() > if pair is None: > pass > else: > sock, addr = pair > print 'Incoming connection from %s' % repr(addr) > handler = Handler(sock) > > server = Server('', 2020) > asyncore.loop() > > I do, however, have some more questions (thus crosspost to > comp.lang.python) - how many connections can this server handle without > a problem? I'm using Asyncore module, as it can be seen. > Is it necessary, due to the fact that it should serve more than > thousand devices that send data every 10 seconds, to do threading (I > believe that is already done with Asyncore for sockets, but what about > SQL?) The MySQL C library is not asynchronous. Each request does blocking I/O. If the MySQLdb module is a wrapper for the MySQL C library--and it seems it is--then you will want to use threads (not coroutines or generators). For all I know your accept handler is threaded already. MySQL itself almost certainly can't handle tens of thousands of simultaneous requests. The backend connection and query handler is simply-threaded as well, which means for every connection your talking 2 * "tens of thousands" threads. I didn't read over your code much, but the only way to get around this would be to handle your socket I/O asynchronously; but I don't enough about Python to get the mixed behavior you'd want. I think that there's an asynchronous all-Python MySQL library, but I'm not sure. Maybe one day I can open source my asynchronous MySQL C library. (I always recommend people to use PostgreSQL, though; which is superior in almost every way, especially the C client library and the wire protocol.) From kwmsmith at gmail.com Wed Feb 16 14:09:04 2011 From: kwmsmith at gmail.com (Kurt Smith) Date: Wed, 16 Feb 2011 13:09:04 -0600 Subject: How to use Python well? In-Reply-To: References: Message-ID: On Wed, Feb 16, 2011 at 12:35 PM, snorble wrote: > I use Python a lot, but not well. I usually start by writing a small > script, no classes or modules. Then I add more content to the loops, > and repeat. It's a bit of a trial and error learning phase, making > sure I'm using the third party modules correctly, and so on. I end up > with a working script, but by the end it looks messy, unorganized, and > feels hacked together. I feel like in order to reuse it or expand it > in the future, I need to take what I learned and rewrite it from > scratch. > > If I peeked over a Python expert's shoulder while they developed > something new, how would their habits differ? Do they start with > classes from the start? > > I guess I'm looking for something similar to "Large Scale C++ Software > Design" for Python. Or even just a walkthrough of someone competent > writing something from scratch. I'm not necessarily looking for a > finished product that is well written. I'm more interested in, "I have > an idea for a script/program, and here is how I get from point A to > point B." > > Or maybe I'm looking for is best practices for how to organize the > structure of a Python program. I love Python and I just want to be > able to use it well. Try this: http://www.refactoring.com/ Not a silver bullet, but a good place to start. From malaclypse2 at gmail.com Wed Feb 16 14:17:28 2011 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 16 Feb 2011 14:17:28 -0500 Subject: unicode shutil.copy() changes a file name during copy? In-Reply-To: <412db27a-3e57-4344-9582-c5f954dbf4ce@f36g2000pri.googlegroups.com> References: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> <412db27a-3e57-4344-9582-c5f954dbf4ce@f36g2000pri.googlegroups.com> Message-ID: On Wed, Feb 16, 2011 at 1:28 PM, dave wrote: > figure it out. ?it's very easy to test it yourself, just make a file > with the section symbol in it, then try to copy it with python 2.7.1 This works fine for me on Windows XP and python 2.6.4 on an NTFS formatted drive. Are either your source or destination network drives? What does sys.getfilesystemencoding() say the encoding of your filesystem is? -- Jerry From fmarshallxremove_the_x at acm.org Wed Feb 16 14:29:39 2011 From: fmarshallxremove_the_x at acm.org (Fred Marshall) Date: Wed, 16 Feb 2011 11:29:39 -0800 Subject: Python Newbie needs some context Message-ID: I can already program in a few languages (but not C++) and, since Python comes to highly recommended, I figured to venture into it. I'm used to using an IDE. So, after some web browsing and reading, I did the following: Installed Python Installed EasyEclipse Installed wxPython Installed wxGlade My objective is to develop some relatively simple GUI applications. Since I'm still on a steep learning curve with all these things I'm clearly missing some of the structural context and wonder where would be really good places to read about: 1) Is it the intent to generate code with wxGlade and then rather "import" that code into an Eclipse project context? Or, should one expect to be able to create hooks (e.g. for Tools) in Eclipse that will do that? If so, how? 2) I'm finding the Eclipse terminology re: projects, folders, etc. etc. rather obscure. Where can I learn about "good practice" and these things. I know what cvs is but won't likely be using it. That is, which item in the hierarchy is best used for what? Thanks, Fred From nickname at banelli.biz.invalid Wed Feb 16 14:40:48 2011 From: nickname at banelli.biz.invalid (Bubba) Date: 16 Feb 2011 19:40:48 GMT Subject: How to handle sockets - easily? References: <878vxo9jeo.fsf@araminta.anjou.terraraq.org.uk> Message-ID: William Ahern's log on stardate 16 vlj 2011 /snip > I think that there's an asynchronous all-Python MySQL library, but > I'm not sure. Maybe one day I can open source my asynchronous MySQL C > library. (I always recommend people to use PostgreSQL, though; which > is superior in almost every way, especially the C client library and > the wire protocol.) I have no particular problem with using PgSQL. Which of these would you recommend? http://wiki.postgresql.org/wiki/Python -- "If you lie to the compiler, it will get its revenge." Henry Spencer 2.718281828459045235360287471352662497757247093699959574966967627.com From invalid at invalid.invalid Wed Feb 16 14:45:12 2011 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Feb 2011 19:45:12 +0000 (UTC) Subject: Python Newbie needs some context References: Message-ID: On 2011-02-16, Fred Marshall wrote: > I can already program in a few languages That should make things easy. > (but not C++) That should help even more > and, since Python comes to highly recommended, I figured to venture > into it. > > I'm used to using an IDE. > > So, after some web browsing and reading, I did the following: > > Installed Python > Installed EasyEclipse > Installed wxPython > Installed wxGlade > > My objective is to develop some relatively simple GUI applications. I wouldn't start with GUI development _unless_ you're already pretty experienced with the particular GUI framework (e.g. wxWindows & Glade). > Since I'm still on a steep learning curve with all these things I'm > clearly missing some of the structural context and wonder where would > be really good places to read about: > > 1) Is it the intent to generate code with wxGlade and then rather > "import" that code into an Eclipse project context? Or, should > one expect to be able to create hooks (e.g. for Tools) in Eclipse > that will do that? If so, how? > > 2) I'm finding the Eclipse terminology re: projects, folders, etc. > etc. rather obscure. Where can I learn about "good practice" and > these things. I know what cvs is but won't likely be using it. > That is, which item in the hierarchy is best used for what? If I were you I wouldn't try to learn Python, wxWindows, wxGlade, and Eclipse all at the same time. Both wxWindows and Eclipse are huge, complex beasts. Add a new language plus wxGlade on top of that, and you're in for a long, hard, frustrating slog. I'd pick a simple IDE or syntax aware editor and learn Python first (without GUI stuff). Once you're comfortable with Python and the IDE, then try to learn wxWindows and wxGlade. If you really want to jump into GUI stuff right away, tkinter is much easier to get started with. -- Grant Edwards grant.b.edwards Yow! I like the way ONLY at their mouths move ... They gmail.com look like DYING OYSTERS From brian.curtin at gmail.com Wed Feb 16 14:47:25 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Wed, 16 Feb 2011 13:47:25 -0600 Subject: logging module -- better timestamp accuracy on Windows In-Reply-To: References: <6fdaebe9-3be4-4163-a769-0e2e018c6c37@y35g2000prc.googlegroups.com> Message-ID: On Wed, Feb 16, 2011 at 12:23, benhoyt wrote: > > > AFAIK, the Windows performance counter has long-term accuracy issues, > > so neither is perfect. Preferably we should have a timer with the long- > > term accuracy of time.time and the short-term accuracy of time.clock. > > Thanks for the tip -- yes, I hadn't thought about that, but you're right, > QueryPerformanceCounter (and hence time.clock) veers away from the system > time, and it's non-trivial to fix. See also: > > http://msdn.microsoft.com/en-us/magazine/cc163996.aspx This is what http://pypi.python.org/pypi/timer uses, although it doesn't go as far as using the final result of the article, but an implementation from Figure 2, which was "Good Enough" (TM). -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at whoosh.ca Wed Feb 16 14:50:17 2011 From: matt at whoosh.ca (Matt Chaput) Date: Wed, 16 Feb 2011 14:50:17 -0500 Subject: Editor/IDE with Python coverage support? Message-ID: Are there any editors/IDEs with good support for line-coloring from Python test coverage results? (I normally use Eclipse + PyDev but PyDev's current coverage support isn't much better than nothing.) Thanks, Matt From victorsubervi at gmail.com Wed Feb 16 14:58:05 2011 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 16 Feb 2011 15:58:05 -0400 Subject: Another MySQLdb Q Message-ID: Hi; I have this code: db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() cursor.execute(sql, id) db.commit() It throws no errors and gives every indication that it executes the command. I've printed out the command and the id and executed it successfully in mysql...but not in python from the script. Everything else works in MySQLdb. What could be the problem? TIA, Beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From anbaricforce at gmail.com Wed Feb 16 15:08:26 2011 From: anbaricforce at gmail.com (dave) Date: Wed, 16 Feb 2011 12:08:26 -0800 (PST) Subject: unicode shutil.copy() changes a file name during copy? References: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> <412db27a-3e57-4344-9582-c5f954dbf4ce@f36g2000pri.googlegroups.com> Message-ID: ah! an interesting point! hmm yes when i'm running parallels, both the source and destination are sortof "Network Drive"'s, they're actually my native mac drives (file system reported as "PrlSF"). In this situation all works well. the reported getfilesystemencoding() is 'mbcs' which is a convenient lie according to the python docs: "On Windows NT+, file names are Unicode natively, so no conversion is performed. getfilesystemencoding() still returns 'mbcs', as this is the encoding that applications should use when they explicitly want to convert Unicode strings to byte strings that are equivalent when used as file names". when i run natively, the drive is NOT a network drive, it is my mac drive supported by "MacDrive" and the file system is reported as "HFSJ". it seems the getfilesystemencoding() should take a drive letter as a parameter cuz the encoding can be different per drive? maybe? but now i think perhaps the problem is with MacDrive? but it works flawlessly with all other software. hmmm. From andrea.crotti.0 at gmail.com Wed Feb 16 15:20:53 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Wed, 16 Feb 2011 21:20:53 +0100 Subject: interfacing python with emacs Message-ID: I decided that I finally want to get auto-completion and other really cool things for my python/emacs environment. Rope also looks really great and being able to refactor easily would really be a dream :) (no more excuses from java developers then) http://rope.sourceforge.net/ Pymacs is already there and working, but it gives me many concerns, so I would like to rewrite something simple and small. Should not be too hard, I just need a server on the python side and a small protocol. So here it comes the first question, how would you make them communicate? In Pymacs was just read and write from stdin/out, but maybe there are better ways. Probably a pipe would be more suited, and maybe even sockets would be nice. But considering how it should be used maybe it doesn't help so much. And what about the protocol? What could be a minimal useful set of operations to do? In the beginning I'll just evaluate python code and get the output, but eventually I want to be able to call python functions as they were elisp functions, which is the main goal. As soon as there is something working I'll publish it on github, so that anyone interested can help/criticize... Thanks, Andrea From anbaricforce at gmail.com Wed Feb 16 15:27:18 2011 From: anbaricforce at gmail.com (dave) Date: Wed, 16 Feb 2011 12:27:18 -0800 (PST) Subject: unicode shutil.copy() changes a file name during copy? References: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> <412db27a-3e57-4344-9582-c5f954dbf4ce@f36g2000pri.googlegroups.com> Message-ID: <001018a6-ff7b-4b61-a51a-c416b1092c57@r4g2000prm.googlegroups.com> ah! an interesting point! hmm yes when i'm running parallels, both the source and destination are sortof "Network Drive"'s, they're actually my native mac drives (file system reported as "PrlSF"). In this situation all works well. the reported getfilesystemencoding() is 'mbcs' which is a convenient lie according to the python docs: "On Windows NT+, file names are Unicode natively, so no conversion is performed. getfilesystemencoding() still returns 'mbcs', as this is the encoding that applications should use when they explicitly want to convert Unicode strings to byte strings that are equivalent when used as file names". when i run natively, the drive is NOT a network drive, it is my mac drive supported by "MacDrive" and the file system is reported as "HFSJ". it seems the getfilesystemencoding() should take a drive letter as a parameter cuz the encoding can be different per drive? maybe? but now i think perhaps the problem is with MacDrive? but it works flawlessly with all other software. hmmm. From gsowww at yahoo.co.uk Wed Feb 16 16:26:26 2011 From: gsowww at yahoo.co.uk (GSO) Date: Wed, 16 Feb 2011 21:26:26 +0000 Subject: Best way to gain root privileges Message-ID: I'm sure this question is as old as time, but what is the best way to gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk v2.18.9, on RHEL6.) Ta, G. gmotion PyGTK desktop GUI for Motion (software motion detector) http://code.google.com/p/gmotion/ From catdude at gmail.com Wed Feb 16 16:29:53 2011 From: catdude at gmail.com (Daniel Mahoney) Date: Wed, 16 Feb 2011 15:29:53 -0600 Subject: Best way to gain root privileges References: Message-ID: On Wed, 16 Feb 2011 21:26:26 +0000, GSO wrote: > I'm sure this question is as old as time, but what is the best way to > gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk > v2.18.9, on RHEL6.) Gain root privileges for a script? Write a c wrapper to call the script, chown it (the wrapper) to root, and set it (the wrapper) suid. From drsalists at gmail.com Wed Feb 16 16:31:15 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 16 Feb 2011 13:31:15 -0800 Subject: Editor/IDE with Python coverage support? In-Reply-To: References: Message-ID: I use vim, but I've considered switching to pycharm. I don't know if pycharm does this or not. Anyway, coverage.py will produce an HTML report describing how well your automated tests cover your code - I like to add it into my Makefile's default rule, and then view the HTML once in a while using a browser. On Wed, Feb 16, 2011 at 11:50 AM, Matt Chaput wrote: > Are there any editors/IDEs with good support for line-coloring from Python test coverage results? (I normally use Eclipse + PyDev but PyDev's current coverage support isn't much better than nothing.) > > Thanks, > > Matt > > -- > http://mail.python.org/mailman/listinfo/python-list > From anbaricforce at gmail.com Wed Feb 16 16:53:18 2011 From: anbaricforce at gmail.com (dave) Date: Wed, 16 Feb 2011 13:53:18 -0800 (PST) Subject: unicode shutil.copy() changes a file name during copy? References: <66ef3b7f-2bff-425f-b44b-8919a83a9ab1@o18g2000prh.googlegroups.com> <412db27a-3e57-4344-9582-c5f954dbf4ce@f36g2000pri.googlegroups.com> Message-ID: thanks to your hint about drive format, i contacted MacDrive and they confirmed it was an incorrect setting, i have since fixed the setting and all is working! not a python bug! thanks for the replies. -dave From steve+comp.lang.python at pearwood.info Wed Feb 16 16:55:12 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Feb 2011 21:55:12 GMT Subject: Best way to gain root privileges References: Message-ID: <4d5c47c0$0$29989$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 Feb 2011 15:29:53 -0600, Daniel Mahoney wrote: > On Wed, 16 Feb 2011 21:26:26 +0000, GSO wrote: > >> I'm sure this question is as old as time, but what is the best way to >> gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk >> v2.18.9, on RHEL6.) > > Gain root privileges for a script? Write a c wrapper to call the script, > chown it (the wrapper) to root, and set it (the wrapper) suid. Further to this: http://www.theillien.com/Sys_Admin_v12/html/v10/i06/a1.htm -- Steven From ian.g.kelly at gmail.com Wed Feb 16 17:02:22 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 Feb 2011 15:02:22 -0700 Subject: Best way to gain root privileges In-Reply-To: References: Message-ID: On Wed, Feb 16, 2011 at 2:29 PM, Daniel Mahoney wrote: > On Wed, 16 Feb 2011 21:26:26 +0000, GSO wrote: > >> I'm sure this question is as old as time, but what is the best way to >> gain root privileges? ?(Am using Python 2.6.5, pygtk2 v2.16, Gtk >> v2.18.9, on RHEL6.) > > Gain root privileges for a script? Write a c wrapper to call the script, > chown it (the wrapper) to root, and set it (the wrapper) suid. Or for better security, write a shell script that execs the Python script via sudo. From xahlee at gmail.com Wed Feb 16 17:07:56 2011 From: xahlee at gmail.com (Xah Lee) Date: Wed, 16 Feb 2011 14:07:56 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages Message-ID: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> might be interesting. ?Problems of Symbol Congestion in Computer Languages (ASCII Jam; Unicode; Fortress)? http://xahlee.org/comp/comp_lang_unicode.html -------------------------------------------------- Problems of Symbol Congestion in Computer Languages (ASCII Jam; Unicode; Fortress) Xah Lee, 2011-02-05, 2011-02-15 Vast majority of computer languages use ASCII as its character set. This means, it jams multitude of operators into about 20 symbols. Often, a symbol has multiple meanings depending on contex. Also, a sequence of chars are used as a single symbol as a workaround for lack of symbols. Even for languages that use Unicode as its char set (e.g. Java, XML), often still use the ~20 ASCII symbols for all its operators. The only exceptions i know of are Mathematica, Fortress, APL. This page gives some examples of problems created by symbol congestion. ------------------------------- Symbol Congestion Workarounds -------------------- Multiple Meanings of a Symbol Here are some common examples of a symbol that has multiple meanings depending on context: In Java, [ ] is a delimiter for array, also a delimiter for getting a element of array, also as part of the syntax for declaring a array type. In Java and many other langs, ( ) is used for expression grouping, also as delimiter for arguments of a function call, also as delimiters for parameters of a function's declaration. In Perl and many other langs, : is used as a separator in a ternary expression e.g. (test ? "yes" : "no"), also as a namespace separator (e.g. use Data::Dumper;). In URL, / is used as path separators, but also as indicator of protocol. e.g. http://example.org/comp/unicode.html In Python and many others, < is used for ?less than? boolean operator, but also as a alignment flag in its ?format? method, also as a delimiter of named group in regex, and also as part of char in other operators that are made of 2 chars, e.g.: << <= <<= <>. -------------------- Examples of Multip-Char Operators Here are some common examples of operators that are made of multiple characters: || && == <= != ** =+ =* := ++ -- :: // /* (* ? ------------------------------- Fortress ? Unicode The language designer Guy Steele recently gave a very interesting talk. See: Guy Steele on Parallel Programing. In it, he showed code snippets of his language Fortress, which freely uses Unicode as operators. For example, list delimiters are not the typical curly bracket {1,2,3} or square bracket [1,2,3], but the unicode angle bracket ?1,2,3?. (See: Matching Brackets in Unicode.) It also uses the circle plus ? as operator. (See: Math Symbols in Unicode.) ------------------------------- Problems of Symbol Congestion I really appreciate such use of unicode. The tradition of sticking to the 95 chars in ASCII of 1960s is extremely limiting. It creates complex problems manifested in: * String Escape mechanism (C's backslash \n, \/, ?, widely adopted.) * Complex delimiters for strings. (Python's triple quotes and perl's variable delimiters q() q[] q{} m//, and heredoc. (See: Strings in Perl and Python ? Heredoc mechanism in PHP and Perl.) * Crazy leaning toothpicks syndrome, especially bad in emacs regex. * Complexities in character representation (See: Emacs's Key Notations Explained (/r, ^M, C-m, RET, , M-, meta) ? HTML entities problems. See: HTML Entities, Ampersand, Unicode, Semantics.) * URL Percent Encoding problems and complexities: Javascript Encode URL, Escape String All these problems occur because we are jamming so many meanings into about 20 symbols in ASCII. See also: * Computer Language Design: Strings Syntax * HTML6: Your JSON and SXML Simplified Most of today's languages do not support unicode in function or variable names, so you can forget about using unicode in variable names (e.g. ?=3) or function names (e.g. ?lambda? as ??? or ?function? as ???), or defining your own operators (e.g. ???). However, there are a few languages i know that do support unicode in function or variable names. Some of these allow you to define your own operators. However, they may not allow unicode for the operator symbol. See: Unicode Support in Ruby, Perl, Python, javascript, Java, Emacs Lisp, Mathematica. Xah From drsalists at gmail.com Wed Feb 16 17:09:52 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 16 Feb 2011 14:09:52 -0800 Subject: How to use Python well? In-Reply-To: References: Message-ID: On Wed, Feb 16, 2011 at 10:35 AM, snorble wrote: > I use Python a lot, but not well. I usually start by writing a small > script, no classes or modules. Then I add more content to the loops, > and repeat. It's a bit of a trial and error learning phase, making > sure I'm using the third party modules correctly, and so on. I end up > with a working script, but by the end it looks messy, unorganized, and > feels hacked together. I feel like in order to reuse it or expand it > in the future, I need to take what I learned and rewrite it from > scratch. To some extent, writing code well just comes from practice with programming, and practice with a language. Exploratory programming is pretty normal (though some still insist on having a complete design before starting on coding), but I find that having lots of automated tests helps make exploratory programming more practical. You may or may not want to read a bit about agile programming: http://en.wikipedia.org/wiki/Agile_software_development A rewrite once in a while is not the end of the world, unless your management decides it is (then it's just a pain to live without the rewrite). ^_^ Oh, and if you use modules and classes and even just functions to limit the impact of one detail on another (each design decision probably should be wrapped up into its own scope somehow), you'll find that rewrites of Portions of your code are pretty viable - without having changes need to cascade through one's codebase. Just saying "I want this to read clearly, not run marginally faster" helps, as does using tools like pylint, pychecker, pyflakes and/or pep8 (pylint probably obviates the pep8 script, but pychecker or pyflakes likely work well in combination with pep8 - so far I've only used pylint). Also, pymetrics is nice for its McCabe Complexity statistic - if the # gets too high, simplify - this often means subdividing large functions or methods into a larger number of smaller functions or methods. But pylint and perhaps others have a warning if your code blocks get too long - that almost gives the same benefit as McCabe. You may find that http://rope.sourceforge.net/ helps with your refactoring, though I have yet to try rope - I just use vim and n.n.n. I hear that some IDE's support refactoring well - pycharm might be a good example. IOW, using some automated tools should give you lots of nearly immediate feedback and assistance in your goal. Yes, some people do start with classes at the outset. Just think of a class as a jack in the box - something with an external view, and a different, hidden, internal view. When you see a need for something like a jack in a box in your code (two different views of what's going on, to limit detail getting scattered more broadly than necessary), consider using a class or perhaps a generator. And yeah, sometimes functions are enough - hey, some functional programming languages have no other means of limiting the impact of details, and there is still some really good functional code out there. Finally, look over someone else's code now and then for ideas; that's a great way to learn. You don't necessarily have to hover over someone's shoulder to learn from them - fortunately we live in a world with symbolic language :). Make sure the copyright on the code won't bite you though. HTH From alister.ware at ntlworld.com Wed Feb 16 17:10:46 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Wed, 16 Feb 2011 22:10:46 GMT Subject: Best way to gain root privileges References: Message-ID: On Wed, 16 Feb 2011 21:26:26 +0000, GSO wrote: > I'm sure this question is as old as time, but what is the best way to > gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk > v2.18.9, on RHEL6.) > > Ta, > > > G. > > gmotion > PyGTK desktop GUI for Motion (software motion detector) > http://code.google.com/p/gmotion/ The easiest way to gain root privileges is to be come sysadmin Credit to the fortune application & the original anonymous poster (sorry Couldn't resist that one) -- Weinberg's Principle: An expert is a person who avoids the small errors while sweeping on to the grand fallacy. From sccolbert at gmail.com Wed Feb 16 17:19:58 2011 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 16 Feb 2011 17:19:58 -0500 Subject: [newbie/2.5.1.1] Computing value of a word? In-Reply-To: References: Message-ID: On Wed, Feb 16, 2011 at 4:27 AM, Chris Rebert wrote: > On Wed, Feb 16, 2011 at 1:17 AM, Gilles Ganault wrote: > > Hello, > > > > For a game, I need to go through a wordlist, and for each word, > > compute its value, ie. a=1, b=2, etc. > > > > So for instance, NewYork = 14 + 5 + 23 + 25 + 15 + 18 + 11 = 111. > > > > Before I write the obvious While loop to go through each line in the > > input text file, I was wondering if Python didn't already have some > > function to perform this type of computation. > > A = ord('a') - 1 > for line in your_file: > word = line.strip().lower() > score = sum(ord(letter)-A for letter in word) > > Or a one-liner (import not included): In [26]: import numpy as np In [27]: (np.frombuffer(buffer('NewYork'.lower()), dtype='uint8') - 96).sum() Out[27]: 111 -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Feb 16 17:33:02 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Feb 2011 17:33:02 -0500 Subject: How to use Python well? In-Reply-To: References: Message-ID: On 2/16/2011 1:35 PM, snorble wrote: > I use Python a lot, but not well. I usually start by writing a small > script, no classes or modules. Then I add more content to the loops, > and repeat. It's a bit of a trial and error learning phase, making > sure I'm using the third party modules correctly, and so on. I end up > with a working script, but by the end it looks messy, unorganized, and > feels hacked together. I feel like in order to reuse it or expand it > in the future, I need to take what I learned and rewrite it from > scratch. Not a completely bad idea, except for the 'from scratch' part. Parts of code that work may just need reorganizing. The most import thing is automated tests. They should grow with the code. Tests are like having a safety net. > If I peeked over a Python expert's shoulder while they developed > something new, how would their habits differ? Do they start with > classes from the start? Depends on whether the particular purpose needs user-defined classes or is fine with functions using built-in classes. -- Terry Jan Reedy From alex.kapps at web.de Wed Feb 16 17:37:24 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Wed, 16 Feb 2011 23:37:24 +0100 Subject: Best way to gain root privileges In-Reply-To: References: Message-ID: <4D5C51A4.3080504@web.de> On 16.02.2011 23:02, Ian Kelly wrote: > On Wed, Feb 16, 2011 at 2:29 PM, Daniel Mahoney wrote: >> On Wed, 16 Feb 2011 21:26:26 +0000, GSO wrote: >> >>> I'm sure this question is as old as time, but what is the best way to >>> gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk >>> v2.18.9, on RHEL6.) >> >> Gain root privileges for a script? Write a c wrapper to call the script, >> chown it (the wrapper) to root, and set it (the wrapper) suid. > > Or for better security, write a shell script that execs the Python > script via sudo. This is what I occasionally use (in a non security critical environment anyway): #!/bin/sh SUDO=gksudo [ -z "$DISPLAY" ] && SUDO=sudo [ "$(id -u)" != 0 ] && exec $SUDO $0 $@ # your_root_privileges_requiring_commands_here Don't ask me for any security issues. Properly setting up a dedicated user group and grant dedicated sudo privileges is probably a better way. HTH From kanthony at woh.rr.com Wed Feb 16 17:42:50 2011 From: kanthony at woh.rr.com (Keith Anthony) Date: Wed, 16 Feb 2011 16:42:50 -0600 Subject: Please post Chuck Missler Bible audio/video Message-ID: Anything from Chuck Missler . I've lost my collection. Thanks. -- --------------------------------- --- -- - Posted with NewsLeecher v4.0 Final Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From emile at fenx.com Wed Feb 16 17:45:41 2011 From: emile at fenx.com (Emile van Sebille) Date: Wed, 16 Feb 2011 14:45:41 -0800 Subject: Best way to gain root privileges In-Reply-To: References: Message-ID: On 2/16/2011 1:26 PM GSO said... > I'm sure this question is as old as time, but what is the best way to > gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk > v2.18.9, on RHEL6.) > have root's password? Emile From steve+comp.lang.python at pearwood.info Wed Feb 16 18:00:35 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Feb 2011 23:00:35 GMT Subject: How to use Python well? References: Message-ID: <4d5c5712$0$29989$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 Feb 2011 10:35:28 -0800, snorble wrote: > I use Python a lot, but not well. I usually start by writing a small > script, no classes or modules. Then I add more content to the loops, and > repeat. It's a bit of a trial and error learning phase, making sure I'm > using the third party modules correctly, and so on. I end up with a > working script, but by the end it looks messy, unorganized, and feels > hacked together. I feel like in order to reuse it or expand it in the > future, I need to take what I learned and rewrite it from scratch. [...] > Or maybe I'm looking for is best practices for how to organize the > structure of a Python program. I love Python and I just want to be able > to use it well. I don't think best practice for writing Python is that much different from best practice for other languages. The main difference is that Python is multi-paradigm: you can mix procedural, functional and object- oriented code in the one program. You should read about bottom-up and top-down programming. You'll probably end up doing some of both, but mostly top-down. The most important thing is structured programming and modularization. The debate over structured programming was won so decisively that people have forgotten that there was ever an argument to be made for spaghetti code! You can learn a lot (and lose a lot of time!) reading the c2.com wiki at http://c2.com/cgi/wiki. These may be useful: http://c2.com/cgi/wiki?StructuredProgramming http://c2.com/cgi/wiki?WhatIsRefactoring Break your code up into small pieces, whether you use functions or classes doesn't really matter, although for small scripts functions are simpler and have less mental overhead. Instead of writing one giant monolithic block of code that does twenty things, write one function for each thing, and then one extra main function to call them. This encourages code reuse, ease of testing, and simplifies maintenance. I find that I've learned more from "things to avoid" than from "things to do". Something about reading about disasters makes it really clear why you shouldn't do it that way :) Avoid: * GOTO, but Python doesn't have that :) * Copy-and-paste programming. If you want to do almost the same thing twice, don't copy the relevant code, paste it, and make a small modification to it. Write one or more functions that handle the common code, and call the function. * Functions that do unrelated things. Functions should do one thing, although that "thing" can get quite complicated. * Don't sweep errors under the rug. Don't catch exceptions unless you can do something about them. "Just ignore it, I'm sure it's not important" is rarely appropriate. See also: http://c2.com/cgi/fullSearch?search=CategoryDevelopmentAntiPattern -- Steven From ben+python at benfinney.id.au Wed Feb 16 18:12:52 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 17 Feb 2011 10:12:52 +1100 Subject: How to use Python well? References: Message-ID: <87sjvnd157.fsf@benfinney.id.au> Terry Reedy writes: > The most import thing is automated tests. Steven D'Aprano writes: > The most important thing is structured programming and modularization. Steel-cage death match. FIGHT! -- \ ?[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.? | _o__) ?Douglas Adams | Ben Finney From roy at panix.com Wed Feb 16 18:21:09 2011 From: roy at panix.com (Roy Smith) Date: Wed, 16 Feb 2011 18:21:09 -0500 Subject: How to use Python well? References: Message-ID: In article , snorble wrote: > I use Python a lot, but not well. I usually start by writing a small > script, no classes or modules. One anti-pattern that I see in my own code is starting out thinking, "this is just a little script, I doesn't need any real structure". That almost always turns out to be wrong, but by the time I start to realize I'm writing spaghetti code, it's so temping to say, "I don't have the time to refactor this now, I'll just hack on it a bit more". Which, of course, makes it even harder to unravel later. The first step is to break up a monolithic script into a few functions. I encourage myself to do that from the git-go by keeping a template around: #!/usr/bin/env python def main(): pass if __name__ == '__main__': main() and I use that whenever I start a new script. That at least gets me off on the right foot. The next step is to turn my collection of functions (with the inevitable collection of global variables that lets them communicate) into a class with methods and instance variables. I can't tell you how many times I've started out saying, "this isn't going to be complicated enough to justify making it a class". Inevitably, I'm wrong. Finally, the next layer of stupid mistake I often make is to start out saying, "This isn't going to be complicated enough to justify writing unit tests". Inevitably, I'm wrong about that too. So far, none of the above is at all specific to Python, It's equally true in any language. Now, for some Python-specific advice; you can write Fortran in any language. What that means is it's one thing to translate some existing script into Python and make it work, but it's another to actually take advantage of some of Python's biggest strengths. Learn to be comfortable with list comprehensions, generator expressions, and iterators in general. Learn about Python's advanced data structures such as sets, defaultdicts, and named tuples. From kwa at kuwata-lab.com Wed Feb 16 18:25:02 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Thu, 17 Feb 2011 08:25:02 +0900 Subject: Method chaining on decorator got SyntaxError Message-ID: Hi, I have a question about decorator. I tried the following example and got Syntax Error. class deco(object): def __init__(self, name): self._name = name def foo(self, value): self._foo = value return self def __call__(self, func): func._deco = self return func ## ok @deco('aaa') def f1(): pass ## Syntax Error @deco('aaa').foo('bbb') # SyntaxError: invalid syntax def f2(): pass The above code shows that Python doesn't allow method chain on decorator syntax. Why does this limitation exist? I want to chain methods as a certain DSL, just like: @recipe().product('*.html').ingreds('$(1).rst') def file_html(c): system(c%"rst2html.py $(ingred) > $(product)") If you know the reason of the restriction, let me know it. -- regards, makoto kuwata From rhodri at wildebst.demon.co.uk Wed Feb 16 18:26:15 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 16 Feb 2011 23:26:15 -0000 Subject: Problem with giant font sizes in tkinter References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> <4d5a25fb$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 15 Feb 2011 07:06:35 -0000, Steven D'Aprano wrote: > On Sun, 13 Feb 2011 23:42:06 +0000, Rhodri James wrote: > >> On Fri, 11 Feb 2011 02:08:01 -0000, Steven D'Aprano >> wrote: >> >>> On Thu, 10 Feb 2011 15:48:47 +0000, Cousin Stanley wrote: >>> >>>> Steven D'Aprano wrote: >>>> >>>>> I have a tkinter application under Python 2.6 which is shows text in >>>>> a giant font, about twenty(?) times larger than expected. > [...] >> In this case I think you're missing a hyphen. Try >> >> titlefont = '-Adobe-Helvetica-Bold-R-Normal--*-180-*' > > Thanks for the suggestion, but xlsfonts returns the same eight font files > regardless of whether the hyphen is there or not. (I wouldn't expect > otherwise, since the font matching treats * as a text wildcard and will > let it cross field boundaries.) Bother. It was a lovely theory, but I should have read the man page first. -- Rhodri James *-* Wildebeest Herder to the Masses From python at mrabarnett.plus.com Wed Feb 16 18:49:30 2011 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 16 Feb 2011 23:49:30 +0000 Subject: Method chaining on decorator got SyntaxError In-Reply-To: References: Message-ID: <4D5C628A.9000606@mrabarnett.plus.com> On 16/02/2011 23:25, Makoto Kuwata wrote: > Hi, > > I have a question about decorator. > I tried the following example and got Syntax Error. > > class deco(object): > def __init__(self, name): > self._name = name > def foo(self, value): > self._foo = value > return self > def __call__(self, func): > func._deco = self > return func > > ## ok > @deco('aaa') > def f1(): pass > > ## Syntax Error > @deco('aaa').foo('bbb') # SyntaxError: invalid syntax > def f2(): pass > > The above code shows that Python doesn't allow method chain > on decorator syntax. > Why does this limitation exist? > I want to chain methods as a certain DSL, just like: > > @recipe().product('*.html').ingreds('$(1).rst') > def file_html(c): > system(c%"rst2html.py $(ingred)> $(product)") > > If you know the reason of the restriction, let me know it. > You may want to read the discussion at: https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en From gsowww at yahoo.co.uk Wed Feb 16 19:00:16 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 00:00:16 +0000 Subject: Best way to gain root privileges In-Reply-To: References: Message-ID: OK, thanks for the tips. gksu* does not seem to be included with RHEL6 Desktop (though there is a package called beesu), and besides which it appears gksu is deprecated[1]. Either way c wrapper or sudo approach it is a tactical decision, and the former is probably a better option with the problem I have (though I will at the end of the day probably use both). I googled c wrapper and there are a ton of issues, type of c system call to use, closing/reopening file handles, etc. Whole books have been written on the subject. The philosophy at the end of the day I think is do your own thing so a hacker cannot download the code you used. [1] http://live.gnome.org/gksu Having said that I'm possibly arriving at the conclusion that a quick perl script might be the simplest/easiest and most secure option - I read perl includes code to safely run suid perl scripts - will dig out my perl tomes. G. On 16 February 2011 22:45, Emile van Sebille wrote: > On 2/16/2011 1:26 PM GSO said... >> >> I'm sure this question is as old as time, but what is the best way to >> gain root privileges? ?(Am using Python 2.6.5, pygtk2 v2.16, Gtk >> v2.18.9, on RHEL6.) >> > > have root's password? > > Emile > > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Wed Feb 16 19:43:22 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Feb 2011 00:43:22 GMT Subject: How to use Python well? References: <87sjvnd157.fsf@benfinney.id.au> Message-ID: <4d5c6f2a$0$29983$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Feb 2011 10:12:52 +1100, Ben Finney wrote: > Terry Reedy writes: > >> The most import thing is automated tests. > > Steven D'Aprano writes: > >> The most important thing is structured programming and modularization. > > > Steel-cage death match. FIGHT! To the death? No, to the pain! http://en.wikiquote.org/wiki/The_Princess_Bride -- Steven From alex.kapps at web.de Wed Feb 16 19:47:10 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Thu, 17 Feb 2011 01:47:10 +0100 Subject: Best way to gain root privileges In-Reply-To: References: Message-ID: <4D5C700E.8070609@web.de> On 17.02.2011 01:00, GSO wrote: > OK, thanks for the tips. > > gksu* does not seem to be included with RHEL6 Desktop (though there is > a package called beesu) On RHEL try consolehelper/userhelper instead which need additional configuration. > The philosophy at the end of the day I think > is do your own thing so a hacker cannot download the code you used. Nonsense. :-) Real crackers don't need to download your source and home-brewed solutions are almost always the wrong solution for security issues (compare: better write your own cryptographic algorithm or use existing ones, even those who are open source?) If public accessible source code would be a security risk, then Linux would be *the* most vulnerable OS ever. Anyway, if you're really that much concerned about security, than drop the whole idea and do not let non-admins perform that job. Or, see if SElinux can help. > Having said that I'm possibly arriving at the conclusion that a quick > perl script might be the simplest/easiest and most secure option - I > read perl includes code to safely run suid perl scripts - will dig out > my perl tomes. Not sure, but Perl is just another "scripting language" (hate that term) and you cannot have scripts be SUID. I have almost no experiences with Perl, but I really doubt, that the general problem would be solved with it. Perhaps explaining your exact situation would help finding a fitting solution. HTH From fmarshallxremove_the_x at acm.org Wed Feb 16 19:56:22 2011 From: fmarshallxremove_the_x at acm.org (Fred Marshall) Date: Wed, 16 Feb 2011 16:56:22 -0800 Subject: Python Newbie needs some context In-Reply-To: References: Message-ID: On 2/16/2011 11:45 AM, Grant Edwards wrote: Thanks for the advice! Is it the intent to generate code with wxGlade and then rather "import" that code into an Eclipse project context? Or, should one expect to be able to create hooks (e.g. for Tools) in Eclipse that will do that? If so, how? Thanks, Fred From calderone.jeanpaul at gmail.com Wed Feb 16 20:20:33 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Wed, 16 Feb 2011 17:20:33 -0800 (PST) Subject: How to handle sockets - easily? References: <878vxo9jeo.fsf@araminta.anjou.terraraq.org.uk> Message-ID: On Feb 16, 1:59?pm, William Ahern wrote: > Bubba wrote: > > > > > > > > > > > > > import asyncore > > import socket > > import string > > import MySQLdb > > import sys > > > ? ? def __init__(self, host, port): > > ? ? ? ? asyncore.dispatcher.__init__(self) > > ? ? ? ? self.create_socket(socket.AF_INET, socket.SOCK_STREAM) > > ? ? ? ? self.set_reuse_addr() > > ? ? ? ? self.bind((host, port)) > > ? ? ? ? self.listen(5) > > > ? ? def handle_accept(self): > > ? ? ? ? pair = self.accept() > > ? ? ? ? if pair is None: > > ? ? ? ? ? ? pass > > ? ? ? ? else: > > ? ? ? ? ? ? sock, addr = pair > > ? ? ? ? ? ? print 'Incoming connection from %s' % repr(addr) > > ? ? ? ? ? ? handler = Handler(sock) > > > server = Server('', 2020) > > asyncore.loop() > > > > I do, however, have some more questions (thus crosspost to > > comp.lang.python) - how many connections can this server handle without > > a problem? I'm using Asyncore module, as it can be seen. > > Is it necessary, due to the fact that it should serve more than > > thousand devices that send data every 10 seconds, to do threading (I > > believe that is already done with Asyncore for sockets, but what about > > SQL?) > > The MySQL C library is not asynchronous. Each request does blocking I/O. If > the MySQLdb module is a wrapper for the MySQL C library--and it seems it > is--then you will want to use threads (not coroutines or generators). For > all I know your accept handler is threaded already. MySQL itself almost > certainly can't handle tens of thousands of simultaneous requests. The > backend connection and query handler is simply-threaded as well, which means > for every connection your talking 2 * "tens of thousands" threads. I didn't > read over your code much, but the only way to get around this would be to > handle your socket I/O asynchronously; but I don't enough about Python to > get the mixed behavior you'd want. > > I think that there's an asynchronous all-Python MySQL library, but I'm not > sure. Maybe one day I can open source my asynchronous MySQL C library. (I > always recommend people to use PostgreSQL, though; which is superior in > almost every way, especially the C client library and the wire protocol.) There's the very new . There's also . Jean-Paul From gsowww at yahoo.co.uk Wed Feb 16 20:40:25 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 01:40:25 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> Message-ID: Apols for being a nuisance. ?I'm normally if anything a web programmer. It looks like there are set-id functions in the os module. ?Further I don't actually need root privileges, just write access to a directory that a user ordinarily does not have write access to (and preferably not read). ?So a call to os.setegid(egid) with a group created for the program's use alone would do this then. ?(Unless this is bad technique security wise otherwise, as a uid 0 seteuid call would be considered; but surely what I am thinking of doing is not a security risk.) > I have almost no experiences with Perl, but I really doubt, that the general > problem would be solved with it. > Quoting from the article linked to by Steven D'Aprano: "If you are new to secure programming, I recommend either sudo or a Perl script. SUID Perl scripts have built-in protection to prevent programmers from making the mistakes addressed in this article." Perl has something called 'tainted mode' built in, which for example will prevent what it judges as untrustworthy data being appended to the end of the passwd file. From kwa at kuwata-lab.com Wed Feb 16 20:55:07 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Thu, 17 Feb 2011 10:55:07 +0900 Subject: Method chaining on decorator got SyntaxError In-Reply-To: <4D5C628A.9000606@mrabarnett.plus.com> References: <4D5C628A.9000606@mrabarnett.plus.com> Message-ID: Thank you MRAB, On Thu, Feb 17, 2011 at 8:49 AM, MRAB wrote: > You may want to read the discussion at: > > https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en > -- I can't figure out what is the point or conclusion of that discussion. Is there any technical reason? Or Ideological reason? -- regards, makoto kuwata From drsalists at gmail.com Wed Feb 16 21:00:43 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 16 Feb 2011 18:00:43 -0800 Subject: Best way to gain root privileges In-Reply-To: <4D5C700E.8070609@web.de> References: <4D5C700E.8070609@web.de> Message-ID: On Wed, Feb 16, 2011 at 4:47 PM, Alexander Kapps wrote: > On 17.02.2011 01:00, GSO wrote: >> Having said that I'm possibly arriving at the conclusion that a quick >> perl script might be the simplest/easiest and most secure option - I >> read perl includes code to safely run suid perl scripts - will dig out >> my perl tomes. > > Not sure, but Perl is just another "scripting language" (hate that term) and > you cannot have scripts be SUID. > > I have almost no experiences with Perl, but I really doubt, that the general > problem would be solved with it. It depends on what OS you're on: #1 On some OS's, setuid #! is an instant root - the script doesn't even need to run. In fact, the problem hinges on the script not running. #2 On others, setuid #! is safe. Or rather, safe if you write your script pretty carefully. #3 On still others, setuid #! doesn't change your access at all; it's just run under the uid that started the script. The perl folk have attempted to make #2 safer with their "taint" stuff (think "dataflow for user inputs to avoid invoking subshells with user inputted data"). There's not a lot they could do about #1 - perl doesn't really enter the picture there. And for #3, you still need a wrapper of some sort, otherwise your script doesn't change users. So yeah, whether you use perl or anything else invoked with #!, you're pretty much better off with sudo, or a tiny C wrapper that's so simple it's hard to get wrong. However, perl's taint feature would be useful irrespective when writing privileged code; it removes some of the skill required. From william at wilbur.25thandClement.com Wed Feb 16 21:05:51 2011 From: william at wilbur.25thandClement.com (William Ahern) Date: Wed, 16 Feb 2011 18:05:51 -0800 Subject: How to handle sockets - easily? References: <878vxo9jeo.fsf@araminta.anjou.terraraq.org.uk> Message-ID: Bubba wrote: > William Ahern's log on stardate 16 vlj 2011 > /snip > > I think that there's an asynchronous all-Python MySQL library, but > > I'm not sure. Maybe one day I can open source my asynchronous MySQL C > > library. (I always recommend people to use PostgreSQL, though; which > > is superior in almost every way, especially the C client library and > > the wire protocol.) > I have no particular problem with using PgSQL. > Which of these would you recommend? http://wiki.postgresql.org/wiki/Python I don't use Python so I couldn't recommend one over another. I just took an interest in your earlier post because I saw MySQL and asynchronous mentioned together. It instantly occurred to me that there might be a conflict there, and quickly reading the Python MySQLdb manual page confirmed this because it seemed clear that it was just binding the C client API. The PostgreSQL C client API supports asynchronous I/O, and the API and protocol support interleaved requests over a single connection. But it's up to the Python module writer to expose that functionality, and expose it in a convenient and stylistically proper manner. Even if all the modules expose the functionality, as I don't work in Python I couldn't say which does it better. Also, of course, there's no substitute for testing. For your particular needs in your particular environment MySQL may work more performantly even with its faults and the kludgy workarounds necessary. I was just warning that you can't let a single client connection hold onto a MySQL connection object for the duration of the client connection's lifetime, and probably don't want the SQL requests to occur on the same thread as the client handlers; at least without understanding the consequences. From gsowww at yahoo.co.uk Wed Feb 16 21:10:55 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 02:10:55 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> Message-ID: > pretty much better off with sudo, or a tiny C wrapper that's so simple > it's hard to get wrong. ?However, perl's taint feature would be useful This snippet is about as tiny as it gets in C I think: #include int main (int argc, char ** argv) { int err; char *newenv[] = { NULL }; if ((err = execle("/usr/bin/pauseme", "pauseme", NULL, newenv)) < 0 ) { exit(err); } return 0; // never reached! } http://linuxgazette.net/67/tag/20.html But even this is considered to be risky. From python at mrabarnett.plus.com Wed Feb 16 21:40:31 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 17 Feb 2011 02:40:31 +0000 Subject: Method chaining on decorator got SyntaxError In-Reply-To: References: <4D5C628A.9000606@mrabarnett.plus.com> Message-ID: <4D5C8A9F.9030904@mrabarnett.plus.com> On 17/02/2011 01:55, Makoto Kuwata wrote: > Thank you MRAB, > > On Thu, Feb 17, 2011 at 8:49 AM, MRAB wrote: >> You may want to read the discussion at: >> >> https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en >> -- > > I can't figure out what is the point or conclusion of that discussion. > Is there any technical reason? Or Ideological reason? > Ideological. Keep it simple. "Readability, not succinctness, is what's Pythonic." -- Mike Meyer From askutt at gmail.com Wed Feb 16 21:44:05 2011 From: askutt at gmail.com (Adam Skutt) Date: Wed, 16 Feb 2011 18:44:05 -0800 (PST) Subject: Best way to gain root privileges References: <4D5C700E.8070609@web.de> Message-ID: On Feb 16, 8:40?pm, GSO wrote: > Apols for being a nuisance. ?I'm normally if anything a web programmer. > > It looks like there are set-id functions in the os module. ?Further I > don't actually need root privileges, just write access to a directory > that a user ordinarily does not have write access to (and preferably > not read). So give them that instead, preferably via ACL. Reliably denying read access may be difficult, however. Chances are pretty good that any solution you create won't be any more secure than this, though. > ?So a call to os.setegid(egid) with a group created for the > program's use alone would do this then. (Unless this is bad technique > security wise otherwise, as a uid 0 seteuid call would be considered; > but surely what I am thinking of doing is not a security risk.) Except in order to do this you need to be root, of course, or make the users members of that group anyway (in which case, just use the damn ACL). Adam From kwa at kuwata-lab.com Wed Feb 16 21:57:42 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Thu, 17 Feb 2011 11:57:42 +0900 Subject: Method chaining on decorator got SyntaxError In-Reply-To: <4D5C8A9F.9030904@mrabarnett.plus.com> References: <4D5C628A.9000606@mrabarnett.plus.com> <4D5C8A9F.9030904@mrabarnett.plus.com> Message-ID: On Thu, Feb 17, 2011 at 11:40 AM, MRAB wrote: > On 17/02/2011 01:55, Makoto Kuwata wrote: >> >> Thank you MRAB, >> >> On Thu, Feb 17, 2011 at 8:49 AM, MRAB ?wrote: >>> >>> You may want to read the discussion at: >>> >>> >>> https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en >>> -- >> >> I can't figure out what is the point or conclusion of that discussion. >> Is there any technical reason? Or Ideological reason? >> > Ideological. > > Keep it simple. > > "Readability, not succinctness, is what's Pythonic." -- Mike Meyer Thank you, MRAB. I'm sad about this restriction because: @recipe.product('*.html').ingreds('$(1).rst') def file_html(c): # do something is enough simple and more readable than: @recipe.product('*.html') @recipe.ingreds('$(1).rst') def file_html(c): # do something But I'll follow the Python's philosophy. -- regards, makoto kuwata From askutt at gmail.com Wed Feb 16 21:59:58 2011 From: askutt at gmail.com (Adam Skutt) Date: Wed, 16 Feb 2011 18:59:58 -0800 (PST) Subject: Best way to gain root privileges References: <4D5C700E.8070609@web.de> Message-ID: <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> On Feb 16, 9:00?pm, Dan Stromberg wrote: > So yeah, whether you use perl or anything else invoked with #!, you're > pretty much better off with sudo, or a tiny C wrapper that's so simple > it's hard to get wrong. UNIX makes this almost impossible unless your wrapper is cooperative with whatever process invokes it, which is itself a security risk. I advise anyone seriously considering this route to take a long, hard look at just what contortions sudo goes through in order to achieve this safety. A correct suid program is neither tiny nor simple. Passing things through sudo(1) is really the only sensible route these days but even that can be fraught with peril. For something as simple as, 'Write to a normally restricted area' it's probably no more secure than an ACL (and potentially way less if you screw up the sudo configuration). > However, perl's taint feature would be useful > irrespective when writing privileged code; it removes some of the > skill required. I don't really think so. It doesn't help prevent, for example, someone redirecting stdout to /etc/shadow and then running your command. Besides, I'm not even remotely convinced that 'removing skill' is a good idea. It especially doesn't help you very much when the whole point of your script is just a wrapper to elevate privileges (execute another programs) or copy files about. Adam From nobody at nowhere.com Wed Feb 16 22:07:19 2011 From: nobody at nowhere.com (Nobody) Date: Thu, 17 Feb 2011 03:07:19 +0000 Subject: Best way to gain root privileges References: Message-ID: On Thu, 17 Feb 2011 01:47:10 +0100, Alexander Kapps wrote: >> Having said that I'm possibly arriving at the conclusion that a quick >> perl script might be the simplest/easiest and most secure option - I >> read perl includes code to safely run suid perl scripts - will dig out >> my perl tomes. > > Not sure, but Perl is just another "scripting language" (hate that > term) and you cannot have scripts be SUID. Perl installations may include a setuid version of the Perl interpreter under the name "sperl", which effectively allows you to have setuid Perl scripts. From gsowww at yahoo.co.uk Wed Feb 16 22:43:32 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 03:43:32 +0000 Subject: Best way to gain root privileges In-Reply-To: <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: > > Passing things through sudo(1) is really the only sensible route these > days but even that can be fraught with peril. ?For something as simple > as, 'Write to a normally restricted area' it's probably no more secure > than an ACL (and potentially way less if you screw up the sudo > configuration). > OK, so I'm heading towards sudo then, aiming to make sure I don't screw up the configuration. This is a home CCTV application, so I want things as secure as possible. A setgid wrapper would require the kind of skilled programming that I couldn't do myself in order to keep things at a high level of security, but sudo I can handle. There is also policykit http://live.gnome.org/PolicyKit which I mentioned in the initial post I think - not sure if this python lib can be used to do what I need though... https://fedorahosted.org/python-slip/ From gsowww at yahoo.co.uk Wed Feb 16 22:53:24 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 03:53:24 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: I essentially don't want to take a risk with a home CCTV prog., so unless I can persuade a highly skilled Unix programmer to write a wrapper (which I can't), then I think I'm best sticking with sudo. From wuwei23 at gmail.com Wed Feb 16 22:56:41 2011 From: wuwei23 at gmail.com (alex23) Date: Wed, 16 Feb 2011 19:56:41 -0800 (PST) Subject: Method chaining on decorator got SyntaxError References: <4D5C628A.9000606@mrabarnett.plus.com> <4D5C8A9F.9030904@mrabarnett.plus.com> Message-ID: <19d14863-b97e-45b8-9302-75b6352b8398@o7g2000prn.googlegroups.com> Makoto Kuwata wrote: > I'm sad about this restriction because: > > ? ? @recipe.product('*.html').ingreds('$(1).rst') > ? ? def file_html(c): > ? ? ? ? # do something > > is enough simple and more readable than: > > ? ? @recipe.product('*.html') > ? ? @recipe.ingreds('$(1).rst') > ? ? def file_html(c): > ? ? ? ? # do something > > But I'll follow the Python's philosophy. Personally, I'd find this approach a lot clearer: rst2html = recipe.product('*.html').ingred('$(1).rst') @rst2html def file_html(c): # etc It allows for easier reuse of your decorators and it labels it in a way that I can understand from the name as opposed to having to decipher the decorator method chain to work out its intent. From cs at zip.com.au Wed Feb 16 23:34:00 2011 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 17 Feb 2011 15:34:00 +1100 Subject: Is this a bug of str.join? In-Reply-To: References: Message-ID: <20110217043400.GA8981@cskk.homeip.net> On 16Feb2011 12:01, Terry Reedy wrote: | On 2/16/2011 1:32 AM, fireinice wrote: | >I'm sorry, I found it should be the terminal width caused visual | >problem, please kindly ignore this post. | | For future reference, the way to get more info about what is really | in a string is to print its repr(), or even its list() version. | Len() is also helpful. On Windows, both the Command Prompt window | and IDLE refuse to expand tabs, so | | >>> s='\t'.join(('a','b','c')) | >>> str(s) | 'a\tb\tc' | >>> repr(s) | "'a\\tb\\tc'" | >>> len(s) | 5 | >>> list(s) | ['a', '\t', 'b', '\t', 'c'] And on UNIX, a common way to inspect program output at the character level is like this: python my_python-program | od -c possibly sent off into a temp file. That will let you see what character are actually escaping from the program (versus terry's suggestion, which is good for looking at the characters before they escape). Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I'm not making any of this up you know. - Anna Russell From andrea.gavana at gmail.com Wed Feb 16 23:58:59 2011 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Thu, 17 Feb 2011 09:58:59 +0500 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy Message-ID: Hi All, I apologize in advance if I'm going to write very stupid things, my expertise in http/socket/imap stuff is very close to zero. I'm using Python 2.6.5 on Windows XP SP3. I am trying to access my GMail account from my office, and it appears our company's firewall is blocking all SMTP/POP3/IMAP attempts or there is simply something I don't understand. My first try was to use imaplib as follows: import imaplib m = imaplib.IMAP4_SSL('imap.gmail.com', 443) m.login(username, password) And I get the following: Traceback (most recent call last): File "D:\MyProjects\gmail.py", line 17, in m = imaplib.IMAP4_SSL('imap.gmail.com', 443) File "C:\Python26\lib\imaplib.py", line 1138, in __init__ IMAP4.__init__(self, host, port) File "C:\Python26\lib\imaplib.py", line 163, in __init__ self.open(host, port) File "C:\Python26\lib\imaplib.py", line 1150, in open self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) File "C:\Python26\lib\ssl.py", line 350, in wrap_socket suppress_ragged_eofs=suppress_ragged_eofs) File "C:\Python26\lib\ssl.py", line 118, in __init__ self.do_handshake() File "C:\Python26\lib\ssl.py", line 293, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [Errno 8] _ssl.c:480: EOF occurred in violation of protocol OK. Then I googled back and forth for a possible solution, and I got a hint that (maybe) the problem could be related to proxy authentication. And I tried this solution (which uses SocksiPy) I found on the web (username2 and password2 are the user name and password for our company's proxy): import socks import socket proxy_ip = "10.100.100.20" # Your proxy IP/DNS here socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy_ip, 8080, True, username2, password2) socket.socket = socks.socksocket import imaplib m = imaplib.IMAP4_SSL('imap.gmail.com', 443) m.login(username, password) This solution just hangs forever at the line: m = imaplib.IMAP4_SSL('imap.gmail.com', 443) And it never returns (it never gets to the m.login() stuff). Then I tried with libgmail, giving it the option of setting the proxy name and port: import libgmail # Connect from behind a proxy www.myproxy.org:3128 using # proxy authentication user = 'john', password = 'proxy4321' libgmail.PROXY_URL = username2:password2 at my_company_proxy:443' # Define the proxy ga = libgmail.GmailAccount(username, password) ga.login() And I got this at first: Traceback (most recent call last): File "D:\MyProjects\gmail2.py", line 8, in ga.login() File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login pageData = self._retrievePage(req) File "C:\Python26\lib\site-packages\libgmail.py", line 340, in _retrievePage req = ClientCookie.Request(urlOrRequest) File "C:\Python26\lib\site-packages\mechanize\_request.py", line 31, in __init__ if not _rfc3986.is_clean_uri(url): File "C:\Python26\lib\site-packages\mechanize\_rfc3986.py", line 63, in is_clean_uri return not bool(BAD_URI_CHARS_RE.search(uri)) TypeError: expected string or buffer Then I brutally hacked into mechanize here and there and I was able to fix all non-internet related errors. And when I try the libgmail solution above now I get: Traceback (most recent call last): File "D:\MyProjects\gmail2.py", line 8, in ga.login() File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login pageData = self._retrievePage(req) File "C:\Python26\lib\site-packages\libgmail.py", line 348, in _retrievePage resp = self.opener.open(req) File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in open response = urlopen(self, req, data) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 344, in _open '_open', req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 332, in _call_chain result = func(*args) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1171, in https_open return self.do_open(conn_factory, req) File "C:\Python26\lib\site-packages\gmail_transport.py", line 145, in do_open return ClientCookie.HTTPSHandler.do_open(self, ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, self.proxy_passwd), req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1118, in do_open raise URLError(err) urllib2.URLError: Just in case, I have tried also with port 80, with similar results: Traceback (most recent call last): File "D:\MyProjects\gmail2.py", line 8, in ga.login() File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login pageData = self._retrievePage(req) File "C:\Python26\lib\site-packages\libgmail.py", line 348, in _retrievePage resp = self.opener.open(req) File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in open response = urlopen(self, req, data) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 344, in _open '_open', req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 332, in _call_chain result = func(*args) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1171, in https_open return self.do_open(conn_factory, req) File "C:\Python26\lib\site-packages\gmail_transport.py", line 145, in do_open return ClientCookie.HTTPSHandler.do_open(self, ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, self.proxy_passwd), req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1118, in do_open raise URLError(err) urllib2.URLError: What am I doing wrong? Is there anything I should do differently? Or anything else I should try? Thank you for your help, any suggestion is highly appreciated. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ ==> Never *EVER* use RemovalGroup for your house removal. You'll regret it forever. http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <== From drsalists at gmail.com Thu Feb 17 00:23:02 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 16 Feb 2011 21:23:02 -0800 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> Message-ID: On Wed, Feb 16, 2011 at 6:10 PM, GSO wrote: >> pretty much better off with sudo, or a tiny C wrapper that's so simple >> it's hard to get wrong. ?However, perl's taint feature would be useful > > This snippet is about as tiny as it gets in C I think: Well, it could be tinier really, and actually, this isn't that bad. > #include > > int main (int argc, char ** argv) { > int err; > > char *newenv[] = { NULL }; > > if ((err = execle("/usr/bin/pauseme", "pauseme", NULL, newenv)) < 0 ) { > ? ? ? ?exit(err); > ? ? ? ?} > > return 0; // never reached! > } > > http://linuxgazette.net/67/tag/20.html > > But even this is considered to be risky. Some people just like to make security sound impossible; they think it makes them look smarter or something. Then again, this is Linux Gazette, which usually caters to relative Linux novices, so maybe such stern warnings are appropriate (for a while - sometimes novices don't stay novices forever). If you empty the environment, don't spawn a subshell, don't scan the path, avoid reading or writing undefined memory, and carefully check your error returns, you're generally in good shape with something as simple as a wrapper. Yes, simple. The signal vulnerability thing appears to be mostly about exploiting overcomplicated signal handlers in the child process (EG, don't use any system calls in signal handlers - not to be confused with system(3)), and the file descriptor thing ISTR is mostly an issue when someone calls open() without correctly checking for an error return - but something like Python would typically traceback - it wouldn't just pretend things were fine. However, if you still think C wrappers are too complex, I believe there's nothing stopping _you_ from using sudo. From bigblueswope at gmail.com Thu Feb 17 00:28:36 2011 From: bigblueswope at gmail.com (BJ Swope) Date: Thu, 17 Feb 2011 00:28:36 -0500 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: References: Message-ID: Imap is not on port 443. IIRC, it's late and I'm to lazy to even google it right now, but it's port 143 isn't it. On Wed, Feb 16, 2011 at 11:58 PM, Andrea Gavana wrote: > Hi All, > > I apologize in advance if I'm going to write very stupid things, > my expertise in http/socket/imap stuff is very close to zero. I'm > using Python 2.6.5 on Windows XP SP3. > > I am trying to access my GMail account from my office, and it appears > our company's firewall is blocking all SMTP/POP3/IMAP attempts or > there is simply something I don't understand. My first try was to use > imaplib as follows: > > > import imaplib > > m = imaplib.IMAP4_SSL('imap.gmail.com', 443) > m.login(username, password) > > > And I get the following: > > > Traceback (most recent call last): > File "D:\MyProjects\gmail.py", line 17, in > m = imaplib.IMAP4_SSL('imap.gmail.com', 443) > File "C:\Python26\lib\imaplib.py", line 1138, in __init__ > IMAP4.__init__(self, host, port) > File "C:\Python26\lib\imaplib.py", line 163, in __init__ > self.open(host, port) > File "C:\Python26\lib\imaplib.py", line 1150, in open > self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) > File "C:\Python26\lib\ssl.py", line 350, in wrap_socket > suppress_ragged_eofs=suppress_ragged_eofs) > File "C:\Python26\lib\ssl.py", line 118, in __init__ > self.do_handshake() > File "C:\Python26\lib\ssl.py", line 293, in do_handshake > self._sslobj.do_handshake() > ssl.SSLError: [Errno 8] _ssl.c:480: EOF occurred in violation of protocol > > > OK. Then I googled back and forth for a possible solution, and I got a > hint that (maybe) the problem could be related to proxy > authentication. And I tried this solution (which uses SocksiPy) I > found on the web (username2 and password2 are the user name and > password for our company's proxy): > > import socks > import socket > > proxy_ip = "10.100.100.20" # Your proxy IP/DNS here > > socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy_ip, 8080, True, > username2, password2) > socket.socket = socks.socksocket > > import imaplib > > m = imaplib.IMAP4_SSL('imap.gmail.com', 443) > m.login(username, password) > > > This solution just hangs forever at the line: > > m = imaplib.IMAP4_SSL('imap.gmail.com', 443) > > And it never returns (it never gets to the m.login() stuff). > > > Then I tried with libgmail, giving it the option of setting the proxy > name and port: > > import libgmail > > # Connect from behind a proxy www.myproxy.org:3128 using > # proxy authentication user = 'john', password = 'proxy4321' > libgmail.PROXY_URL = username2:password2 at my_company_proxy:443' # > Define the proxy > > ga = libgmail.GmailAccount(username, password) > ga.login() > > > And I got this at first: > > Traceback (most recent call last): > File "D:\MyProjects\gmail2.py", line 8, in > ga.login() > File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login > pageData = self._retrievePage(req) > File "C:\Python26\lib\site-packages\libgmail.py", line 340, in > _retrievePage > req = ClientCookie.Request(urlOrRequest) > File "C:\Python26\lib\site-packages\mechanize\_request.py", line 31, > in __init__ > if not _rfc3986.is_clean_uri(url): > File "C:\Python26\lib\site-packages\mechanize\_rfc3986.py", line 63, > in is_clean_uri > return not bool(BAD_URI_CHARS_RE.search(uri)) > TypeError: expected string or buffer > > > Then I brutally hacked into mechanize here and there and I was able to > fix all non-internet related errors. And when I try the libgmail > solution above now I get: > > Traceback (most recent call last): > File "D:\MyProjects\gmail2.py", line 8, in > ga.login() > File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login > pageData = self._retrievePage(req) > File "C:\Python26\lib\site-packages\libgmail.py", line 348, in > _retrievePage > resp = self.opener.open(req) > File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in > open > response = urlopen(self, req, data) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 344, in _open > '_open', req) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 332, in _call_chain > result = func(*args) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 1171, in https_open > return self.do_open(conn_factory, req) > File "C:\Python26\lib\site-packages\gmail_transport.py", line 145, in > do_open > return ClientCookie.HTTPSHandler.do_open(self, > ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, > self.proxy_passwd), req) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 1118, in do_open > raise URLError(err) > urllib2.URLError: Forbidden ( The ISA Server denied the specified Uniform Resource > Locator (URL). )> > > > Just in case, I have tried also with port 80, with similar results: > > Traceback (most recent call last): > File "D:\MyProjects\gmail2.py", line 8, in > ga.login() > File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login > pageData = self._retrievePage(req) > File "C:\Python26\lib\site-packages\libgmail.py", line 348, in > _retrievePage > resp = self.opener.open(req) > File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in > open > response = urlopen(self, req, data) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 344, in _open > '_open', req) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 332, in _call_chain > result = func(*args) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 1171, in https_open > return self.do_open(conn_factory, req) > File "C:\Python26\lib\site-packages\gmail_transport.py", line 145, in > do_open > return ClientCookie.HTTPSHandler.do_open(self, > ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, > self.proxy_passwd), req) > File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", > line 1118, in do_open > raise URLError(err) > urllib2.URLError: Authentication Required ( The ISA Server requires authorization to > fulfill the request. Access to the Web Proxy filter is denied. )> > > > What am I doing wrong? Is there anything I should do differently? Or > anything else I should try? > > Thank you for your help, any suggestion is highly appreciated. > > > Andrea. > > "Imagination Is The Only Weapon In The War Against Reality." > http://xoomer.alice.it/infinity77/ > > ==> Never *EVER* use RemovalGroup for your house removal. You'll > regret it forever. > http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <== > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.gavana at gmail.com Thu Feb 17 00:37:23 2011 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Thu, 17 Feb 2011 10:37:23 +0500 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: References: Message-ID: Hi, On 17 February 2011 10:28, BJ Swope wrote: > Imap is not on port 443.? IIRC, it's late and I'm to lazy to even google it > right now, but it's port 143 isn't it. I have tried that, and I get the following with imaplib: Traceback (most recent call last): File "D:\MyProjects\gmail.py", line 17, in m = imaplib.IMAP4_SSL('imap.gmail.com', 143) File "C:\Python26\lib\imaplib.py", line 1138, in __init__ IMAP4.__init__(self, host, port) File "C:\Python26\lib\imaplib.py", line 163, in __init__ self.open(host, port) File "C:\Python26\lib\imaplib.py", line 1149, in open self.sock = socket.create_connection((host, port)) File "C:\Python26\lib\socket.py", line 514, in create_connection raise error, msg socket.error: [Errno 10061] No connection could be made because the target machine actively refused it And this one with libgmail: Traceback (most recent call last): File "D:\MyProjects\gmail2.py", line 8, in ga.login() File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login pageData = self._retrievePage(req) File "C:\Python26\lib\site-packages\libgmail.py", line 348, in _retrievePage resp = self.opener.open(req) File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in open response = urlopen(self, req, data) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 344, in _open '_open', req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 332, in _call_chain result = func(*args) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1171, in https_open return self.do_open(conn_factory, req) File "C:\Python26\lib\site-packages\gmail_transport.py", line 143, in do_open return ClientCookie.HTTPSHandler.do_open(self, ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, self.proxy_passwd), req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1118, in do_open raise URLError(err) urllib2.URLError: :-( :-( Thank you for your answer. > On Wed, Feb 16, 2011 at 11:58 PM, Andrea Gavana > wrote: >> >> Hi All, >> >> ? ?I apologize in advance if I'm going to write very stupid things, >> my expertise in http/socket/imap stuff is very close to zero. I'm >> using Python 2.6.5 on Windows XP SP3. >> >> I am trying to access my GMail account from my office, and it appears >> our company's firewall is blocking all SMTP/POP3/IMAP attempts or >> there is simply something I don't understand. My first try was to use >> imaplib as follows: >> >> >> import imaplib >> >> m = imaplib.IMAP4_SSL('imap.gmail.com', 443) >> m.login(username, password) >> >> >> And I get the following: >> >> >> Traceback (most recent call last): >> ?File "D:\MyProjects\gmail.py", line 17, in >> ? ?m = imaplib.IMAP4_SSL('imap.gmail.com', 443) >> ?File "C:\Python26\lib\imaplib.py", line 1138, in __init__ >> ? ?IMAP4.__init__(self, host, port) >> ?File "C:\Python26\lib\imaplib.py", line 163, in __init__ >> ? ?self.open(host, port) >> ?File "C:\Python26\lib\imaplib.py", line 1150, in open >> ? ?self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) >> ?File "C:\Python26\lib\ssl.py", line 350, in wrap_socket >> ? ?suppress_ragged_eofs=suppress_ragged_eofs) >> ?File "C:\Python26\lib\ssl.py", line 118, in __init__ >> ? ?self.do_handshake() >> ?File "C:\Python26\lib\ssl.py", line 293, in do_handshake >> ? ?self._sslobj.do_handshake() >> ssl.SSLError: [Errno 8] _ssl.c:480: EOF occurred in violation of protocol >> >> >> OK. Then I googled back and forth for a possible solution, and I got a >> hint that (maybe) the problem could be related to proxy >> authentication. And I tried this solution (which uses SocksiPy) I >> found on the web (username2 and password2 are the user name and >> password for our company's proxy): >> >> import socks >> import socket >> >> proxy_ip = "10.100.100.20" ? # Your proxy IP/DNS here >> >> socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy_ip, 8080, True, >> username2, password2) >> socket.socket = socks.socksocket >> >> import imaplib >> >> m = imaplib.IMAP4_SSL('imap.gmail.com', 443) >> m.login(username, password) >> >> >> This solution just hangs forever at the line: >> >> m = imaplib.IMAP4_SSL('imap.gmail.com', 443) >> >> And it never returns (it never gets to the m.login() stuff). >> >> >> Then I tried with libgmail, giving it the option of setting the proxy >> name and port: >> >> import libgmail >> >> # Connect from behind a proxy www.myproxy.org:3128 using >> # proxy authentication user = 'john', password = 'proxy4321' >> libgmail.PROXY_URL = username2:password2 at my_company_proxy:443' ?# >> Define the proxy >> >> ga = libgmail.GmailAccount(username, password) >> ga.login() >> >> >> And I got this at first: >> >> Traceback (most recent call last): >> ?File "D:\MyProjects\gmail2.py", line 8, in >> ? ?ga.login() >> ?File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login >> ? ?pageData = self._retrievePage(req) >> ?File "C:\Python26\lib\site-packages\libgmail.py", line 340, in >> _retrievePage >> ? ?req = ClientCookie.Request(urlOrRequest) >> ?File "C:\Python26\lib\site-packages\mechanize\_request.py", line 31, >> in __init__ >> ? ?if not _rfc3986.is_clean_uri(url): >> ?File "C:\Python26\lib\site-packages\mechanize\_rfc3986.py", line 63, >> in is_clean_uri >> ? ?return not bool(BAD_URI_CHARS_RE.search(uri)) >> TypeError: expected string or buffer >> >> >> Then I brutally hacked into mechanize here and there and I was able to >> fix all non-internet related errors. And when I try the libgmail >> solution above now I get: >> >> Traceback (most recent call last): >> ?File "D:\MyProjects\gmail2.py", line 8, in >> ? ?ga.login() >> ?File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login >> ? ?pageData = self._retrievePage(req) >> ?File "C:\Python26\lib\site-packages\libgmail.py", line 348, in >> _retrievePage >> ? ?resp = self.opener.open(req) >> ?File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in >> open >> ? ?response = urlopen(self, req, data) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 344, in _open >> ? ?'_open', req) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 332, in _call_chain >> ? ?result = func(*args) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 1171, in https_open >> ? ?return self.do_open(conn_factory, req) >> ?File "C:\Python26\lib\site-packages\gmail_transport.py", line 145, in >> do_open >> ? ?return ClientCookie.HTTPSHandler.do_open(self, >> ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, >> self.proxy_passwd), req) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 1118, in do_open >> ? ?raise URLError(err) >> urllib2.URLError: > Forbidden ( The ISA Server denied the specified Uniform Resource >> Locator (URL). ?)> >> >> >> Just in case, I have tried also with port 80, with similar results: >> >> Traceback (most recent call last): >> ?File "D:\MyProjects\gmail2.py", line 8, in >> ? ?ga.login() >> ?File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login >> ? ?pageData = self._retrievePage(req) >> ?File "C:\Python26\lib\site-packages\libgmail.py", line 348, in >> _retrievePage >> ? ?resp = self.opener.open(req) >> ?File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in >> open >> ? ?response = urlopen(self, req, data) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 344, in _open >> ? ?'_open', req) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 332, in _call_chain >> ? ?result = func(*args) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 1171, in https_open >> ? ?return self.do_open(conn_factory, req) >> ?File "C:\Python26\lib\site-packages\gmail_transport.py", line 145, in >> do_open >> ? ?return ClientCookie.HTTPSHandler.do_open(self, >> ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, >> self.proxy_passwd), req) >> ?File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", >> line 1118, in do_open >> ? ?raise URLError(err) >> urllib2.URLError: > Authentication Required ( The ISA Server requires authorization to >> fulfill the request. Access to the Web Proxy filter is denied. ?)> >> >> >> What am I doing wrong? Is there anything I should do differently? Or >> anything else I should try? >> >> Thank you for your help, any suggestion is highly appreciated. >> >> >> Andrea. >> >> "Imagination Is The Only Weapon In The War Against Reality." >> http://xoomer.alice.it/infinity77/ >> >> ==> Never *EVER* use RemovalGroup for your house removal. You'll >> regret it forever. >> http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <== >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ ==> Never *EVER* use RemovalGroup for your house removal. You'll regret it forever. http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <== From mgreene at bdurham.com Thu Feb 17 01:44:36 2011 From: mgreene at bdurham.com (Malcolm Greene) Date: Thu, 17 Feb 2011 01:44:36 -0500 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: References: Message-ID: <1297925076.8054.1421127991@webmail.messagingengine.com> Andrea, What type of result do you get trying port 993 ? Malcolm From drsalists at gmail.com Thu Feb 17 02:12:13 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 16 Feb 2011 23:12:13 -0800 Subject: Best way to gain root privileges In-Reply-To: <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: On Wed, Feb 16, 2011 at 6:59 PM, Adam Skutt wrote: > On Feb 16, 9:00 pm, Dan Stromberg wrote: >> So yeah, whether you use perl or anything else invoked with #!, you're >> pretty much better off with sudo, or a tiny C wrapper that's so simple >> it's hard to get wrong. > > UNIX makes this almost impossible Please give a source that includes justifying detail. Then you have the right to ask me if there are well understood ways around each of the issues identified. > unless your wrapper is cooperative > with whatever process invokes it Isn't this what we were discussing? I know I was. Other than you and I both suggesting sudo as an alternative, that is. > , which is itself a security risk. I > advise anyone seriously considering this route to take a long, hard > look at just what contortions sudo goes through in order to achieve > this safety. A correct suid program is neither tiny nor simple. Actually, they can be. Here's one, as a very easy-to-find example: $ ls -al cmd started 2011 Wed Feb 16 10:19:21 PM total 8 drwxr-xr-x 2 dstromberg dstromberg 4096 2011-02-16 22:19 . drwxr-xr-x 61 dstromberg dstromberg 4096 2011-02-16 22:18 .. -rwsr-xr-x 1 root dstromberg 0 2011-02-16 22:19 correct-and-simple-setuid benchbox-dstromberg:~/src/correct-and-simple-setuid i686-pc-linux-gnu 12006 - above cmd done 2011 Wed Feb 16 10:19 PM $ ./correct-and-simple-setuid cmd started 2011 Wed Feb 16 10:19:24 PM benchbox-dstromberg:~/src/correct-and-simple-setuid i686-pc-linux-gnu 12006 - above cmd done 2011 Wed Feb 16 10:19 PM $ echo $? cmd started 2011 Wed Feb 16 10:19:26 PM 0 benchbox-dstromberg:~/src/correct-and-simple-setuid i686-pc-linux-gnu 12006 - above cmd done 2011 Wed Feb 16 10:19 PM It's a correct, setuid replacement for /bin/true. It's 0 bytes long. Now, I expect you to exploit it, since I claim that it's both tiny and simple. IOW, it's a reductio ad absurdum. sudo is an example of something that _isn't_ closely matched with what it's running (beyond a little text in a config file), not something that _is_. You're engaging in a category error there. In fact, sudo has a _lot_ of extra complexity to achieve a degree of genericity. A better example is apache suexec - the helper portion of which is 428 physical SLOC, and it's more complex than most need to be because it keeps many env vars and prunes out others. > Passing things through sudo(1) is really the only sensible route these > days but even that can be fraught with peril. Wait - I thought you just said that it was almost impossible unless the setuid wrapper was well matched with the program in question. Oh, you did. Or was writing sudo almost impossible? Well, no, it may have some expert knowledge built into it, but I believe it was just a mechanical process of translating a surmountable number of bugtraq discussions into code. > For something as simple > as, 'Write to a normally restricted area' it's probably no more secure > than an ACL (and potentially way less if you screw up the sudo > configuration). ACL's aren't at all unreasonable, though I believe they'll likely yield a superset of the same problems one would see with a sticky directory. But then, neither are setgid and setuid unreasonable - with setgid being preferred over setuid. >> However, perl's taint feature would be useful >> irrespective when writing privileged code; it removes some of the >> skill required. > > I don't really think so. It doesn't help prevent, for example, > someone redirecting stdout to /etc/shadow and then running your > command. Quantifier error: You've given an example of why taint isn't perfect, not a proof of why it's useless. I said it would be useful, not that it was 100% trouble free. Moreover, I'd like to see your code demonstrating the ability to make a simple setuid wrapper that doesn't even open a file, append to /etc/shadow. If you'd like, I'll write the wrapper for you. Note that >> is performed by the shell, not the wrapper. If that unprivileged shell (or unprivileged C program, or whatever) can >> /etc/shadow, then you've got bigger problems to worry about. Oh, did you mean the _subprogram_ could be exploited? Why didn't you say so? And why is this an attribute of the wrapper, and not an attribute of the subprogram? IOW, you appear to be reasoning that because the _subprogram_ the wrapper invokes /might/ be flawed, the teensy setuid _wrapper_ /definitely/is/inherently/ broken. This, assuming you're really suggesting this, is both a category error and a quantifier error. > Besides, I'm not even remotely convinced that 'removing > skill' is a good idea. Fine. Forget Python. Forget C. Forget assembly language. Forget machine language. Forget firmware programming. Forget plugboards. Forget GUI's. Forget curses. Forget command line. Forget punch cards. Forget toggle switches. In fact, forget electricity where it might remove skill. Since removing skill is a bad idea, I expect that you'll greatly prefer to perform your "coding" using levers and gears, along the lines of the Antikythera mechanism. Then again, maybe you're a little more hardcore than that, and would prefer to forsake automation, forsake handwriting and do your computations strictly in your head. Reductio ad absurdum again. Sigh. > It especially doesn't help you very much when the whole point of your > script is just a wrapper to elevate privileges (execute another > programs) or copy files about. Did we change the subject again? I'm talking about a C wrapper for a script. Are you talking about a script wrapper for a script? You're confusing me. ^_^ -------------- next part -------------- An HTML attachment was scrubbed... URL: From w_a_x_man at yahoo.com Thu Feb 17 02:19:43 2011 From: w_a_x_man at yahoo.com (WJ) Date: 17 Feb 2011 07:19:43 GMT Subject: toy list processing problem: collect similar terms References: Message-ID: Xah Lee wrote: > here's a interesting toy list processing problem. > > I have a list of lists, where each sublist is labelled by > a number. I need to collect together the contents of all sublists > sharing > the same label. So if I have the list > > ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q > r) (5 s t)) > > where the first element of each sublist is the label, I need to > produce: > > output: > ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) > Solving without hash-tables or "group-by". Using Guile: First, sort the groups by the numbers. (stable-sort groups (lambda(a b)(< (car a) (car b)))) ((0 a b) (1 c d) (1 i j) (2 e f) (2 k l) (2 o p) (3 g h) (4 m n) (4 q r) (5 s t)) Next, flatten the list. (append-map identity step1) (0 a b 1 c d 1 i j 2 e f 2 k l 2 o p 3 g h 4 m n 4 q r 5 s t) Remove duplicate numbers. (delete-duplicates step2) (0 a b 1 c d i j 2 e f k l o p 3 g h 4 m n q r 5 s t) We now need a very useful function called "scan". ;; Yields sublists of contiguous items that satisfy func. (define (scan func lst) (let ((tail (find-tail func lst))) (if tail (cons (take-while func tail) (scan func (drop-while func tail))) '()))) (scan symbol? step3) ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t)) From clp2 at rebertia.com Thu Feb 17 02:53:46 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 16 Feb 2011 23:53:46 -0800 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: <1297925076.8054.1421127991@webmail.messagingengine.com> References: <1297925076.8054.1421127991@webmail.messagingengine.com> Message-ID: On Wed, Feb 16, 2011 at 10:44 PM, Malcolm Greene wrote: > Andrea, > > What type of result do you get trying port 993 ? i.e. The port Google explicitly says to use for IMAP in Gmail's help docs. Cheers, Chris From wdahn at netfront.net Thu Feb 17 03:27:11 2011 From: wdahn at netfront.net (Werner) Date: Thu, 17 Feb 2011 16:27:11 +0800 Subject: Newbie getting desperate with for Message-ID: I have a trivially simple piece of code called timewaster.py: ____________________________________________________ while True: i = 0 for i in range(10): break _____________________________________________________ It runs fine with Eric but when I try to run it from shell... > ./timewaster.py ./timewaster.py: line 4: syntax error near unexpected token `(' ./timewaster.py: line 4: ` for i in range(10):' I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python version 2.6.5, both show the above. Before I tear out my hair any more (only 3 left) I thought I'd ask here what I am doing wrong. Best Regards Werner Dahn From nitinpawar432 at gmail.com Thu Feb 17 03:37:58 2011 From: nitinpawar432 at gmail.com (Nitin Pawar) Date: Thu, 17 Feb 2011 14:07:58 +0530 Subject: Newbie getting desperate with for In-Reply-To: References: Message-ID: can you share the first line of your shell (shabang) ? I think you have forgotten to tell the shell which interpreter to use if you have not put #!/usr/bin/python then its plain shell script which is incorrect On Thu, Feb 17, 2011 at 1:57 PM, Werner wrote: > I have a trivially simple piece of code called timewaster.py: > ____________________________________________________ > > while True: > i = 0 > for i in range(10): > break > _____________________________________________________ > > It runs fine with Eric but when I try to run it from shell... > > ./timewaster.py > ./timewaster.py: line 4: syntax error near unexpected token `(' > ./timewaster.py: line 4: ` for i in range(10):' > > I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python > version 2.6.5, both show the above. > > Before I tear out my hair any more (only 3 left) I thought I'd ask here > what I am doing wrong. > > Best Regards > Werner Dahn > -- > http://mail.python.org/mailman/listinfo/python-list > -- Nitin Pawar -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Feb 17 03:39:01 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 17 Feb 2011 00:39:01 -0800 Subject: Newbie getting desperate with for In-Reply-To: References: Message-ID: On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: > I have a trivially simple piece of code called timewaster.py: > ____________________________________________________ > > while True: > ? ?i = 0 > ? ?for i in range(10): > ? ? ? ?break > _____________________________________________________ > > It runs fine with Eric but when I try to run it from shell... >> ./timewaster.py > ./timewaster.py: line 4: syntax error near unexpected token `(' > ./timewaster.py: line 4: ` ? ?for i in range(10):' > > I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python > version 2.6.5, both show the above. > > Before I tear out my hair any more (only 3 left) I thought I'd ask here > what I am doing wrong. Looks like it's being run as a shell script rather than through the Python interpreter (hence why the error is not in the form of an exception with a traceback). Try adding: #!/usr/bin/env python as the first line in your file. This tells the shell to run the script using Python. Or alternatively, instead of: ./timewaster.py use: python timewaster.py which likewise explicitly invokes the Python interpreter. Cheers, Chris -- http://blog.rebertia.com From wdahn at netfront.net Thu Feb 17 03:42:05 2011 From: wdahn at netfront.net (Werner) Date: Thu, 17 Feb 2011 16:42:05 +0800 Subject: Newbie getting desperate with for In-Reply-To: References: Message-ID: On 17/02/11 16:39, Chris Rebert wrote: > On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: >> I have a trivially simple piece of code called timewaster.py: >> ____________________________________________________ >> >> while True: >> i = 0 >> for i in range(10): >> break >> _____________________________________________________ >> >> It runs fine with Eric but when I try to run it from shell... >>> ./timewaster.py >> ./timewaster.py: line 4: syntax error near unexpected token `(' >> ./timewaster.py: line 4: ` for i in range(10):' >> >> I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python >> version 2.6.5, both show the above. >> >> Before I tear out my hair any more (only 3 left) I thought I'd ask here >> what I am doing wrong. > > Looks like it's being run as a shell script rather than through the > Python interpreter (hence why the error is not in the form of an > exception with a traceback). > > Try adding: > > #!/usr/bin/env python > > as the first line in your file. This tells the shell to run the script > using Python. > > Or alternatively, instead of: > > ./timewaster.py > > use: > > python timewaster.py > > which likewise explicitly invokes the Python interpreter. > > Cheers, > Chris > -- > http://blog.rebertia.com Yes, that was it. AYAA! Thank you very much. From andrea.gavana at gmail.com Thu Feb 17 03:56:29 2011 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Thu, 17 Feb 2011 13:56:29 +0500 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: <1297925076.8054.1421127991@webmail.messagingengine.com> References: <1297925076.8054.1421127991@webmail.messagingengine.com> Message-ID: Hi Malcolm, On 17 February 2011 11:44, Malcolm Greene wrote: > Andrea, > > What type of result do you get trying port 993 ? Thank you for your answer. I have tried that, with imaplib and libgmail. This is what I get with imaplib: Traceback (most recent call last): File "D:\MyProjects\gmail.py", line 17, in m = imaplib.IMAP4_SSL('imap.gmail.com', 993) File "C:\Python26\lib\imaplib.py", line 1138, in __init__ IMAP4.__init__(self, host, port) File "C:\Python26\lib\imaplib.py", line 163, in __init__ self.open(host, port) File "C:\Python26\lib\imaplib.py", line 1149, in open self.sock = socket.create_connection((host, port)) File "C:\Python26\lib\socket.py", line 514, in create_connection raise error, msg socket.error: [Errno 10061] No connection could be made because the target machine actively refused it And this with libgmail: Traceback (most recent call last): File "D:\MyProjects\gmail2.py", line 10, in ga.login() File "C:\Python26\lib\site-packages\libgmail.py", line 305, in login pageData = self._retrievePage(req) File "C:\Python26\lib\site-packages\libgmail.py", line 348, in _retrievePage resp = self.opener.open(req) File "C:\Python26\lib\site-packages\mechanize\_opener.py", line 193, in open response = urlopen(self, req, data) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 344, in _open '_open', req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 332, in _call_chain result = func(*args) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1171, in https_open return self.do_open(conn_factory, req) File "C:\Python26\lib\site-packages\gmail_transport.py", line 143, in do_open return ClientCookie.HTTPSHandler.do_open(self, ProxyHTTPSConnection.new_auth(self.proxy, self.proxy_user, self.proxy_passwd), req) File "C:\Python26\lib\site-packages\mechanize\_urllib2_fork.py", line 1118, in do_open raise URLError(err) urllib2.URLError: This thing is driving me crazy, and I'm not even doing it for fun... Thank you for your suggestions. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ ==> Never *EVER* use RemovalGroup for your house removal. You'll regret it forever. http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <== From flebber.crue at gmail.com Thu Feb 17 04:53:12 2011 From: flebber.crue at gmail.com (flebber) Date: Thu, 17 Feb 2011 01:53:12 -0800 (PST) Subject: How to use Python well? References: <87sjvnd157.fsf@benfinney.id.au> <4d5c6f2a$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 17, 11:43?am, Steven D'Aprano wrote: > On Thu, 17 Feb 2011 10:12:52 +1100, Ben Finney wrote: > > Terry Reedy writes: > > >> The most import thing is automated tests. > > > Steven D'Aprano writes: > > >> The most important thing is structured programming and modularization. > > > Steel-cage death match. FIGHT! > > To the death? No, to the pain! > > http://en.wikiquote.org/wiki/The_Princess_Bride > > -- > Steven I really liked Abstraction Chapter 6 & 7 In Magnus Lie Hetlands book novice to professional. It really show the how to "think it out" which seems to be what your after. The first sub heading in Chapter 6 is "Laziness is a virtue" can't beat that. From clp2 at rebertia.com Thu Feb 17 05:05:45 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 17 Feb 2011 02:05:45 -0800 Subject: How to use Python well? In-Reply-To: References: <87sjvnd157.fsf@benfinney.id.au> <4d5c6f2a$0$29983$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Feb 17, 2011 at 1:53 AM, flebber wrote: > On Feb 17, 11:43?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Thu, 17 Feb 2011 10:12:52 +1100, Ben Finney wrote: >> > Terry Reedy writes: >> >> >> The most import thing is automated tests. >> >> > Steven D'Aprano writes: >> >> >> The most important thing is structured programming and modularization. >> >> > Steel-cage death match. FIGHT! > > I really liked Abstraction Chapter 6 & 7 In Magnus Lie Hetlands book > novice to professional. It really show the how to "think it out" which > seems to be what your after. The first sub heading in Chapter 6 is > "Laziness is a virtue" can't beat that. Related: http://c2.com/cgi/wiki?LazinessImpatienceHubris Cheers, Chris From andrea.crotti.0 at gmail.com Thu Feb 17 05:11:56 2011 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 17 Feb 2011 11:11:56 +0100 Subject: 2to3 Message-ID: What would be an almost automated way to develop for both python 2.x and 3.x? 2to3 apparently can only output a diff or write directly on the file (with -w), but why doesn't it output the resulting file for 3.x instead? So for a single python file I tried a makefile like: Makefile: all: empathy.py cp empathy.py empathy3.py 2to3 -w empathy3.py But maybe there's a better way using python tools... Then after that how do I test the various versions with the various python versions in a portable way? I could just have a bash script that calls python2 empathy.py python3 empathy3.py but it's probably not very portable.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Thu Feb 17 05:12:51 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Feb 2011 10:12:51 GMT Subject: Method chaining on decorator got SyntaxError References: <4D5C628A.9000606@mrabarnett.plus.com> <4D5C8A9F.9030904@mrabarnett.plus.com> <19d14863-b97e-45b8-9302-75b6352b8398@o7g2000prn.googlegroups.com> Message-ID: alex23 wrote: > Makoto Kuwata wrote: >> I'm sad about this restriction because: >> >> ? ? @recipe.product('*.html').ingreds('$(1).rst') >> ? ? def file_html(c): >> ? ? ? ? # do something >> >> is enough simple and more readable than: >> >> ? ? @recipe.product('*.html') >> ? ? @recipe.ingreds('$(1).rst') >> ? ? def file_html(c): >> ? ? ? ? # do something >> >> But I'll follow the Python's philosophy. > > Personally, I'd find this approach a lot clearer: > > rst2html = recipe.product('*.html').ingred('$(1).rst') > > @rst2html > def file_html(c): > # etc > > It allows for easier reuse of your decorators and it labels it in a > way that I can understand from the name as opposed to having to > decipher the decorator method chain to work out its intent. Or another way would be to define `recipe` such that something like this works: @recipe(product='*.html', ingreds='$(1).rst') def file_html(c): ... -- Duncan Booth http://kupuguy.blogspot.com From clp2 at rebertia.com Thu Feb 17 05:32:28 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 17 Feb 2011 02:32:28 -0800 Subject: 2to3 In-Reply-To: References: Message-ID: On Thu, Feb 17, 2011 at 2:11 AM, andrea crotti wrote: > What would be an almost automated way to develop for both python 2.x and > 3.x? > Then after that how do I test the various versions with the various python > versions in a portable way? > > I could just have a bash script that calls > > python2 empathy.py > python3 empathy3.py > > but it's probably not very portable.. Actually, so long as you specify a bit more specific versions, e.g.: python2.7 empathy.py python3.1 empathy3.py it should be fine on most *nixes. Windows would of course require a separate, but analogous, batch file or similar. As for porting the tests themselves, yes, that could be an issue. Cheers, Chris From pstatham at sefas.com Thu Feb 17 05:40:22 2011 From: pstatham at sefas.com (pstatham) Date: Thu, 17 Feb 2011 02:40:22 -0800 (PST) Subject: Connecting to remote Oracle db via Python Message-ID: <1e4f8836-20ff-4317-8c30-047ef6ec0c71@4g2000yqo.googlegroups.com> Hi Guys, I've installed the cx_Oracle module for Python and I'm trying to connect to my remote Oracle db. Like so (username, password and ip below aren't real don't worry) >>> uid = "scott" >>> pwd = "tiger" >>> service = "10.5.1.12:1521:PR10" >>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) This however gives me the following error: Traceback (most recent call last): File "", line 1, in cx_Oracle.DatabaseError: ORA-12545: Connect failed because target host or object does not exist I've also tried the following (jdbc string which works fine for java) >>> service = "jdbc:oracle:thin:@10.5.1.12:1521:PR10" >>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) Traceback (most recent call last): File "", line 1, in cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified I'm not sure what's going on because I know that the ip, port and service name. are correct? And as I said I can connect to it via JDBC in Java. Any ideas? Thanks, Paul From jeanmichel at sequans.com Thu Feb 17 05:49:07 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 17 Feb 2011 11:49:07 +0100 Subject: return an object of a different class In-Reply-To: References: Message-ID: <4D5CFD23.1070800@sequans.com> spam at uce.gov wrote: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > def __init__(self, n): > self.original_value = n > if n <= 100: > self = SmallNumers(self) > else: > self = BigNumbers(self) > > class SmallNumbers: > def __init__(self, n): > self.size = 'small' > > class BigNumbers: > def __init__(self, n): > self.size = 'big' > > t = MyNumbers(200) > > > When I do type(t) it says MyNumbers, while I'd want it to be > BigNumbers, because BigNumbers and SmallNumbers will have different > methods etc... > > Do I need to use metaclasses? > > Thanks. You simply don't return inconsistent types with a return statement. This is a general rule in programming that has probably exceptions but regarding what you're saying, you clearly don't want to do that. Immagine the following code: oNumber = MyNumbers(random.int(100)) # note that oNumber is not a MyNumbers instance... quite confusing don't you think ? oNumber. ... wait a minute, which methods am I allowed to call ??? SmallNumbers adn BigNumbers have differents methods. Some rules to follow, until you get some experience with python: * use consistent types for method parameters. * use consistent types for returned values. * a class constructor should return an instance of that very same class. JM From andrea.crotti.0 at gmail.com Thu Feb 17 05:49:52 2011 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 17 Feb 2011 11:49:52 +0100 Subject: 2to3 In-Reply-To: References: Message-ID: 2011/2/17 Chris Rebert > > Actually, so long as you specify a bit more specific versions, e.g.: > > python2.7 empathy.py > python3.1 empathy3.py > > it should be fine on most *nixes. Windows would of course require a > separate, but analogous, batch file or similar. As for porting the > tests themselves, yes, that could be an issue. > > Cheers, > Chris > Well ok the test script doesn't have to be portable at all costs, but I think it's something that could be solved with zc.buildout for example. But what about the code itself. How do I import and execute the right version depending on the python version on the system? This can instead probably be done in the setup.py right? Or maybe I can directly check in the makefile and do some linking tricks.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Feb 17 06:02:28 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 17 Feb 2011 12:02:28 +0100 Subject: return an object of a different class In-Reply-To: <4D5B932E.9000206@free.fr> References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> Message-ID: <4D5D0044.4000208@sequans.com> Karim wrote: > [snip] >> If you don't want to use a factory function I believe you can do this: >> >> class MyNumber(object): >> def __new__(cls, n): >> if n<= 100: >> cls = SmallNumbers >> else: >> cls = BigNumbers >> return object.__new__(cls, n) >> ... >> >> Chard. > > Very beautiful code great alternative to factory method! > To memorize this pythonic way. > > Regards > Karim Do you think that the MyNumber constructor returning something else than a MyNumber instance is the pythonic way ? It would rather be the cryptonic way ! (haha) JM From nospam at nospam.com Thu Feb 17 06:20:48 2011 From: nospam at nospam.com (Gilles Ganault) Date: Thu, 17 Feb 2011 12:20:48 +0100 Subject: [newbie/2.5.1.1] Computing value of a word? References: Message-ID: <341ql6ph8thfsl5rom7cdpsuj18psqvs86@4ax.com> On Wed, 16 Feb 2011 01:27:06 -0800, Chris Rebert wrote: >A = ord('a') - 1 >for line in your_file: > word = line.strip().lower() > score = sum(ord(letter)-A for letter in word) Thanks much Chris. From moogyd at yahoo.co.uk Thu Feb 17 06:22:16 2011 From: moogyd at yahoo.co.uk (moogyd) Date: Thu, 17 Feb 2011 03:22:16 -0800 (PST) Subject: Standard Delay Format (SDF) Parsing Message-ID: Hi, A Standard Delay Format (SDF) file is a text file used to store delay information, and is used in ASIC design. I need to parse some of these files and before I re-invent the wheel, is anyone aware of a module to allow parsing of these files? Thanks, Steven From jeanmichel at sequans.com Thu Feb 17 06:29:16 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 17 Feb 2011 12:29:16 +0100 Subject: How to use Python well? In-Reply-To: References: Message-ID: <4D5D068C.1090101@sequans.com> snorble wrote: > I use Python a lot, but not well. I usually start by writing a small > script, no classes or modules. Then I add more content to the loops, > and repeat. It's a bit of a trial and error learning phase, making > sure I'm using the third party modules correctly, and so on. I end up > with a working script, but by the end it looks messy, unorganized, and > feels hacked together. I feel like in order to reuse it or expand it > in the future, I need to take what I learned and rewrite it from > scratch. > > If I peeked over a Python expert's shoulder while they developed > something new, how would their habits differ? Do they start with > classes from the start? > > I guess I'm looking for something similar to "Large Scale C++ Software > Design" for Python. Or even just a walkthrough of someone competent > writing something from scratch. I'm not necessarily looking for a > finished product that is well written. I'm more interested in, "I have > an idea for a script/program, and here is how I get from point A to > point B." > > Or maybe I'm looking for is best practices for how to organize the > structure of a Python program. I love Python and I just want to be > able to use it well. > I guess this is happening to anyone using python for their everyday scripting. Writing tools to make life easier. You start writing some quick and dirty code just to do the trick ASAP. Then after adding some features your realize it became a little more than a script but don't want to share it because the code is just a freaking mess that no one but you can understand. Here are the things I do to avoid getting to that point: 1 - accept the fact that I will lose time trying to write it correcly from the begining 2 - the script has to be "importable" and usable by a 3rd python program. 3 - regulary test my code with the python shell importing the script 4 - use a linter (pylint) with all warnings activated. 5 - document the public class/function. This "force" me to expose the minimum interface, because like everyone, I dislike writing doc 6 - always include a argument parser. 7 - always use the logging module. 8 - if the project starts to become medium, write unitary tests. And maybe the most important one, I always start from the upper level interface down to primitives (top-down programming ?). This helps me making suff really easy to use, with a clean interface. Sometimes the implementation can become tricky that way, I guess it's a matter of preference. In pratice, that just means that I write the method call before writing the method definition. JM From steve+comp.lang.python at pearwood.info Thu Feb 17 06:43:47 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Feb 2011 11:43:47 GMT Subject: return an object of a different class References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> Message-ID: <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote: > Karim wrote: >> [snip] >>> If you don't want to use a factory function I believe you can do this: >>> >>> class MyNumber(object): >>> def __new__(cls, n): >>> if n<= 100: >>> cls = SmallNumbers >>> else: >>> cls = BigNumbers >>> return object.__new__(cls, n) >>> ... >>> >>> Chard. >> >> Very beautiful code great alternative to factory method! To memorize >> this pythonic way. >> >> Regards >> Karim > Do you think that the MyNumber constructor returning something else > than a MyNumber instance is the pythonic way ? It would rather be the > cryptonic way ! (haha) Support for constructors returning something other than an instance of the class is not an accident, it is a deliberate, and useful, design. The Fine Manual says: object.__new__(cls[, ...]) Called to create a new instance of class cls. [...] The return value of __new__() should be the new object instance (usually an instance of cls). [...] If __new__() does not return an instance of cls, then the new instance?s __init__() method will not be invoked. http://docs.python.org/reference/datamodel.html#basic-customization So while it is *usual* for the constructor to return an instance of the class, it's not compulsory, and returning other types is explicitly supported. To answer your question about whether this is Pythonic... here's a small clue from Python 2.5: >>> n = int("4294967296") # 2**32 >>> type(n) So, yes, absolutely, it is not only allowed for class constructors to return an instance of a different class, but there is precedence in the built-ins. -- Steven From davea at ieee.org Thu Feb 17 07:14:46 2011 From: davea at ieee.org (Dave Angel) Date: Thu, 17 Feb 2011 07:14:46 -0500 Subject: 2to3 In-Reply-To: References: Message-ID: <4D5D1136.9040706@ieee.org> On 01/-10/-28163 02:59 PM, andrea crotti wrote: > 2011/2/17 Chris Rebert > >> >> Actually, so long as you specify a bit more specific versions, e.g.: >> >> python2.7 empathy.py >> python3.1 empathy3.py >> >> it should be fine on most *nixes. Windows would of course require a >> separate, but analogous, batch file or similar. As for porting the >> tests themselves, yes, that could be an issue. >> >> Cheers, >> Chris >> > > Well ok the test script doesn't have to be portable at all costs, but I > think it's something that could be solved with zc.buildout for example. > > But what about the code itself. > How do I import and execute the right version depending on the python > version on the system? > > This can instead probably be done in the setup.py right? > Or maybe I can directly check in the makefile and do some linking tricks.. > Don't rename the file you're converting, copy it to a unique directory. And if you have many files, replicate the whole tree. Each version of python has a separate set of import paths, so you should be able to do it systematically without much difference inside your own scripts and modules. To figure out what those import paths look like for your particular system, print out sys.path DaveA From prakash.stack at gmail.com Thu Feb 17 07:38:30 2011 From: prakash.stack at gmail.com (prakash jp) Date: Thu, 17 Feb 2011 18:08:30 +0530 Subject: FIX Message module Message-ID: Hi all, Finacial Information Exchange (FIX) Protocol module is what I am looking for.Using it I would like to pump and listen to the FIX messages--(hard coded values). Please guide me through the relevant module (windows installer) and anything that you foresee as a potential bottleneck. So far I tried using QUICFIX at:*http://www.quickfixengine.org/download.html *, but could not start right away. Thanks in Advance Prakash -------------- next part -------------- An HTML attachment was scrubbed... URL: From askutt at gmail.com Thu Feb 17 07:40:36 2011 From: askutt at gmail.com (Adam Skutt) Date: Thu, 17 Feb 2011 07:40:36 -0500 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: On Thu, Feb 17, 2011 at 2:12 AM, Dan Stromberg wrote: > > On Wed, Feb 16, 2011 at 6:59 PM, Adam Skutt wrote: >> On Feb 16, 9:00?pm, Dan Stromberg wrote: >>> So yeah, whether you use perl or anything else invoked with #!, you're >>> pretty much better off with sudo, or a tiny C wrapper that's so simple >>> it's hard to get wrong. >> >> UNIX makes this almost impossible > > Please give a source that includes justifying detail. ?Then you have the > right to ask me if there are well understood ways around each of the issues > identified. I did, the sudo source; kindly read the whole paragraph before replying next time. Do you think they go through all the contortions regarding closing FDs, handling signals, etc. just for fun? Do you think what they go through is unnecessary? No, the correct and portable ways to do many of the necessary actions are hardly obvious. Almost impossible refers to the fact that tasks that ought to be relatively simple, like closing all file descriptors, aren't made trivial by any standard. Heck, even figuring out what file descriptors might need to be closed is non-trivial! There is no one convenient source that plainly documents everything you must do and why, beyond the source code of applications that already escalate privileges safely. In which case, you might as well just run one of them. Very few (any?) programs that run setuid (root) have existed without a security vulnerability in their history. On the continuum from trivial to impossible, writing a program that securely elevates privilege definitely sits much closer to impossible. > Actually, they can be. ?Here's one, as a very easy-to-find example: > > $ ls -al > cmd started 2011 Wed Feb 16 10:19:21 PM > total 8 > drwxr-xr-x ?2 dstromberg dstromberg 4096 2011-02-16 22:19 . > drwxr-xr-x 61 dstromberg dstromberg 4096 2011-02-16 22:18 .. > -rwsr-xr-x ?1 root ? ? ? dstromberg ? ?0 2011-02-16 22:19 > correct-and-simple-setuid > benchbox-dstromberg:~/src/correct-and-simple-setuid i686-pc-linux-gnu 12006 > - above cmd done 2011 Wed Feb 16 10:19 PM > > $ ./correct-and-simple-setuid > cmd started 2011 Wed Feb 16 10:19:24 PM > benchbox-dstromberg:~/src/correct-and-simple-setuid i686-pc-linux-gnu 12006 > - above cmd done 2011 Wed Feb 16 10:19 PM > > $ echo $? > cmd started 2011 Wed Feb 16 10:19:26 PM > 0 > benchbox-dstromberg:~/src/correct-and-simple-setuid i686-pc-linux-gnu 12006 > - above cmd done 2011 Wed Feb 16 10:19 PM > > It's a correct, setuid replacement for /bin/true.? It's 0 bytes long.? Now, > I expect you to exploit it, since I claim that it's both tiny and simple. > IOW, it's a reductio ad absurdum. The only absurd part of this example is why I would do this in the first place. If this is the level of discourse you're going to choose to operate at, then I don't see any reason to waste my time any further with you. Counter-examples that do nothing meaningful are themselves meaningless. > > sudo is an example of something that _isn't_ closely matched with what it's > running (beyond a little text in a config file), not something that _is_. > ?You're engaging in a category error there. No, I'm not, the entire point is that any wrapper involving user input in any capacity (including on the part of the program it ends up running) must do most, if not all, of the things sudo does wrt actually running something with privilege. Trying to make assumptions on the part of your parent is folly. > A better example is apache suexec - the helper portion of which is? 428 > physical SLOC, and it's more complex than most need to be because it keeps > many env vars and prunes out others. See http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=511 (among others) You don't want to be Apache suexec, kids! It's also sounds, from GSO's description, rather useless here. >> Passing things through sudo(1) is really the only sensible route these >> days but even that can be fraught with peril. > Wait - I thought you just said that it was almost impossible unless the > setuid wrapper was well matched with the program in question. > > Oh, you did. The entire point of my statement was that such a thing is an impossibility: the wrapper cannot safely make assumptions about whatever calls it. Nor is it permissible to make assumptions about whatever the wrapper calls except in very trivial circumstances. The inherent contradiction is that we want (legitimately) for our wrapper to assume it will only be executed by our own code, to reduce the problems it has to worry about. Unfortunately, UNIX makes this impossible and makes assuming literally nothing the only safe choice. > Quantifier error: You've given an example of why taint isn't perfect, not a > proof of why it's useless.? I said it would be useful, not that it was 100% > trouble free. Those sorts of problems are the hard ones to defend over. You're suggesting taint mode like one would suggest locking one's door, that's great if you want to keep out a thief, but it doesn't even slow down the police with a battering ram! The battering ram is what we want to defend against. So you'll have to forgive me for calling the door lock (taint mode) useless. > Moreover, I'd like to see your code demonstrating the ability to make a > simple setuid wrapper that doesn't even open a file, append to /etc/shadow. > If you'd like, I'll write the wrapper for you. > > Note that >> is performed by the shell, not the wrapper.? If that > unprivileged shell (or unprivileged C program, or whatever) can >> > /etc/shadow, then you've got bigger problems to worry about. Yes, you can't use a shell redirect, mea culpa. Privilege escalation races are nothing new, however: http://www.phreedom.org/solar/vuln/osh/. Taint mode does not save you from those. > Oh, did you mean the _subprogram_ could be exploited?? Why didn't you say > so?? And why is this an attribute of the wrapper, and not an attribute of > the subprogram?? IOW, you appear to be reasoning that because the > _subprogram_ the wrapper invokes /might/ be flawed, the teensy setuid > _wrapper_ /definitely/is/inherently/ broken.? This, assuming you're really > suggesting this, is both a category error and a quantifier error. The entire point of the wrapper is to make the subprogram safe for escalated execution! If the subprogram were already safe for escalated execution, we would just put the setuid bit on it directly and skip the wrapper altogether! This includes even a wrapper for the mere purpose of "executing a script". > >> ?Besides, I'm not even remotely convinced that 'removing >> skill' is a good idea. > > Fine. ?Forget Python.? Forget C.? Forget assembly language.? Forget machine > language.? Forget firmware programming.? Forget plugboards.? Forget GUI's. > Forget curses.? Forget command line.? Forget punch cards.? Forget toggle > switches.? In fact, forget electricity where it might remove skill.? Since > removing skill is a bad idea, I expect that you'll greatly prefer to perform > your "coding" using levers and gears, along the lines of the Antikythera > mechanism.? Then again, maybe you're a little more hardcore than that, and > would prefer to forsake automation, forsake handwriting and do your > computations strictly in your head. > The fact you think any of this is relevant to my point is absolutely gobsmacking. > Did we change the subject again?? I'm talking about a C wrapper for a > script.? Are you talking about a script wrapper for a script?? You're > confusing me.? ^_^ A C wrapper for a script is emphatically not what he needs, he needs a way to copy files to a privileged area. Involving a script in that process seems pretty plainly undesirable, especially in these modern times. Adam From askutt at gmail.com Thu Feb 17 07:43:15 2011 From: askutt at gmail.com (Adam Skutt) Date: Thu, 17 Feb 2011 04:43:15 -0800 (PST) Subject: Best way to gain root privileges References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: On Feb 16, 10:43?pm, GSO wrote: > OK, so I'm heading towards sudo then, aiming to make sure I don't > screw up the configuration. ?This is a home CCTV application, so I > want things as secure as possible. ?A setgid wrapper would require the > kind of skilled programming that I couldn't do myself in order to keep > things at a high level of security, but sudo I can handle. I'm having a awfully hard time figuring out why a home CCTV application might need privilege at all. Are you sure you really need privilege? It sounds to me like there may be some larger design issues mandating the need for privilege when it's not really necessary. Adam From eaglebalti at gmail.com Thu Feb 17 08:02:04 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Thu, 17 Feb 2011 05:02:04 -0800 (PST) Subject: HOT INDIAN WALLPAPER Message-ID: <2935bc2d-4d8b-4a4b-b85b-59f9dcec24cc@f36g2000pri.googlegroups.com> for more detail just visit www.hotdesepix-usa.blogspot.com www.onlinetv-usa.blogspot.com www.onlineradio-usa.blogspot.com From jeanmichel at sequans.com Thu Feb 17 08:38:21 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 17 Feb 2011 14:38:21 +0100 Subject: return an object of a different class In-Reply-To: <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D5D24CD.6000506@sequans.com> Steven D'Aprano wrote: > On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote: > > >> Karim wrote: >> >>> [snip] >>> >>>> If you don't want to use a factory function I believe you can do this: >>>> >>>> class MyNumber(object): >>>> def __new__(cls, n): >>>> if n<= 100: >>>> cls = SmallNumbers >>>> else: >>>> cls = BigNumbers >>>> return object.__new__(cls, n) >>>> ... >>>> >>>> Chard. >>>> >>> Very beautiful code great alternative to factory method! To memorize >>> this pythonic way. >>> >>> Regards >>> Karim >>> >> Do you think that the MyNumber constructor returning something else >> than a MyNumber instance is the pythonic way ? It would rather be the >> cryptonic way ! (haha) >> > > > Support for constructors returning something other than an instance of > the class is not an accident, it is a deliberate, and useful, design. The > Fine Manual says: > > object.__new__(cls[, ...]) > > Called to create a new instance of class cls. [...] > The return value of __new__() should be the new object > instance (usually an instance of cls). > [...] > If __new__() does not return an instance of cls, then > the new instance?s __init__() method will not be invoked. > > > http://docs.python.org/reference/datamodel.html#basic-customization > > So while it is *usual* for the constructor to return an instance of the > class, it's not compulsory, and returning other types is explicitly > supported. > > To answer your question about whether this is Pythonic... here's a small > clue from Python 2.5: > > >>>> n = int("4294967296") # 2**32 >>>> type(n) >>>> > > > > > So, yes, absolutely, it is not only allowed for class constructors to > return an instance of a different class, but there is precedence in the > built-ins. > > Returning another class instance in a new operator is legit, but regarding the documentaiton you quoted, it's also "unusual", for which is used the word "cryptonic" instead. But that was only in the attempt of being clever. But I'm used to that when it comes to joking in english :-/. Thing is, I said the same thing that the __new__ documentation. Concerning the example you've given, you shoud notice that int and long objects have the exact same interface, same attributes. And all their methods mean to do the same thing. In fact it doesn't really matter if you're manipulating an int or a long, you're still using the 2 objects the same way for the same result. From a duck typing POV, they're the same class. This is not what would happen for the OP, given the examples he gave. JM From gleam.uahmed at gmail.com Thu Feb 17 09:03:48 2011 From: gleam.uahmed at gmail.com (uahmed) Date: Thu, 17 Feb 2011 19:03:48 +0500 Subject: Simple Question Message-ID: Why Tkinter on Linux dont support other format of logo picture except of .xbm format ? here logo Picture means an image which comes on top left of window . -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Thu Feb 17 09:20:29 2011 From: python at bdurham.com (python at bdurham.com) Date: Thu, 17 Feb 2011 09:20:29 -0500 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: References: <1297925076.8054.1421127991@webmail.messagingengine.com> Message-ID: <1297952429.21461.1421183197@webmail.messagingengine.com> Hi Andrea, Have you tried temporarily turning off your Windows firewall software and/or any locally installed internet security software like Norton, Avast, etc? You don't need to turn off your entire security package, just the component that controls internet access. If the problem can not be resolved locally, then I believe you need to contact your IT department to have them create the firewall rules that will allow you to access gmail services. I'm basing that suggestion on googling the various error messages (10060, 10061) you received and reading the answers. That's my interpretation, anyway. I'm a big fan of your wxPython and GUI builder contributions!! Regards, Malcolm From msarro at gmail.com Thu Feb 17 09:23:10 2011 From: msarro at gmail.com (Matty Sarro) Date: Thu, 17 Feb 2011 09:23:10 -0500 Subject: First time using an API... Message-ID: This may be kind of a stupid question, so please be gentle. I've only ever used most programming in the past when shell scripting couldn't handle what I needed done. So, I rarely dabble with things like API's, or even python-isms. I just program to get things done. Well, that's about to change :) I am in charge of deploying a platform to allow people across my company to access a variety of crunched metrics using splunk. I need to allow access into the data using Splunk's RESTful API, which is implemented in both java and python. The thing is, I have no idea how to do that. I've looked through some of the documentation, and it has me start a pydoc server on the system but when i navigate to the page it just shows listings of functions. The descriptions would be great, except they don't really tell me a lot. For instance, nothing really seems to say "fetchRecord(user_name) fetches all records matching a particular user name". Further, how do I actually use the API? I appreciate any of the pointers you can offer. Its a big part of this project, but my minor knowledge in programming isn't helping me much here. -Matty From anurag.chourasia at gmail.com Thu Feb 17 09:38:23 2011 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 17 Feb 2011 20:08:23 +0530 Subject: Connecting to remote Oracle db via Python In-Reply-To: <1e4f8836-20ff-4317-8c30-047ef6ec0c71@4g2000yqo.googlegroups.com> References: <1e4f8836-20ff-4317-8c30-047ef6ec0c71@4g2000yqo.googlegroups.com> Message-ID: Could you try by using a connecting string in the standard format as below? Connection_String = 'scott/tiger@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.1.12(PORT=1521)))(CONNECT_DATA=(SID=PR10)))' db = cx_Oracle.connect(Connection_String) Regards, Anurag On Thu, Feb 17, 2011 at 4:10 PM, pstatham wrote: > Hi Guys, > > I've installed the cx_Oracle module for Python and I'm trying to > connect to my remote Oracle db. Like so (username, password and ip > below aren't real don't worry) > >>>> uid = "scott" >>>> pwd = "tiger" >>>> service = "10.5.1.12:1521:PR10" >>>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) > > This however gives me the following error: > > Traceback (most recent call last): > ?File "", line 1, in > cx_Oracle.DatabaseError: ORA-12545: Connect failed because target host > or object > ?does not exist > > I've also tried the following (jdbc string which works fine for java) > >>>> service = "jdbc:oracle:thin:@10.5.1.12:1521:PR10" >>>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) > Traceback (most recent call last): > ?File "", line 1, in > cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect > identifier > ?specified > > I'm not sure what's going on because I know that the ip, port and > service name. are correct? And as I said I can connect to it via JDBC > in Java. > > Any ideas? > > Thanks, > Paul > -- > http://mail.python.org/mailman/listinfo/python-list > From anikom15 at gmail.com Thu Feb 17 09:39:48 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 17 Feb 2011 06:39:48 -0800 Subject: return an object of a different class In-Reply-To: <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1297953588.4951.1.camel@localhost.localdomain> On Thu, 2011-02-17 at 11:43 +0000, Steven D'Aprano wrote: > On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote: > > > Karim wrote: > >> [snip] > >>> If you don't want to use a factory function I believe you can do this: > >>> > >>> class MyNumber(object): > >>> def __new__(cls, n): > >>> if n<= 100: > >>> cls = SmallNumbers > >>> else: > >>> cls = BigNumbers > >>> return object.__new__(cls, n) > >>> ... > >>> > >>> Chard. > >> > >> Very beautiful code great alternative to factory method! To memorize > >> this pythonic way. > >> > >> Regards > >> Karim > > Do you think that the MyNumber constructor returning something else > > than a MyNumber instance is the pythonic way ? It would rather be the > > cryptonic way ! (haha) > > > Support for constructors returning something other than an instance of > the class is not an accident, it is a deliberate, and useful, design. The > Fine Manual says: > > object.__new__(cls[, ...]) > > Called to create a new instance of class cls. [...] > The return value of __new__() should be the new object > instance (usually an instance of cls). > [...] > If __new__() does not return an instance of cls, then > the new instance?s __init__() method will not be invoked. > > > http://docs.python.org/reference/datamodel.html#basic-customization > > So while it is *usual* for the constructor to return an instance of the > class, it's not compulsory, and returning other types is explicitly > supported. > > To answer your question about whether this is Pythonic... here's a small > clue from Python 2.5: > > >>> n = int("4294967296") # 2**32 > >>> type(n) > > > > > So, yes, absolutely, it is not only allowed for class constructors to > return an instance of a different class, but there is precedence in the > built-ins. > > > > -- > Steven Python 3 removed longs because they were ... cryptonic! From anurag.chourasia at gmail.com Thu Feb 17 09:58:27 2011 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 17 Feb 2011 20:28:27 +0530 Subject: Connecting to remote Oracle db via Python In-Reply-To: <2F802216565E44489600A03F763219A8010BAD46@mia.SEFASBRISTOL> References: <1e4f8836-20ff-4317-8c30-047ef6ec0c71@4g2000yqo.googlegroups.com> <3E14881B2E2442D1BD9E842223F00791@SEFASBRISTOL> <2F802216565E44489600A03F763219A8010BAD46@mia.SEFASBRISTOL> Message-ID: Try this please and it should work. Connection_String = 'scott/tiger@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.1.12)(PORT=1521)))(CONNECT_DATA=(SID=PR10)))' db = cx_Oracle.connect(Connection_String) I'm sorry i missed a bracket there. Regards, Anurag On Thu, Feb 17, 2011 at 8:18 PM, Paul Statham wrote: > Doesn't seem to work > > -----Original Message----- > From: Anurag Chourasia [mailto:anurag.chourasia at gmail.com] > Sent: 17 February 2011 14:41 > To: Paul Statham > Cc: python-list at python.org > Subject: Re: Connecting to remote Oracle db via Python > > Could you try by using a connecting string in the standard format as below? > > Connection_String = > 'scott/tiger@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.1.12(PORT=1521)))(CONNECT_DATA=(SID=PR10)))' > > db = cx_Oracle.connect(Connection_String) > > Regards, > Anurag > > On Thu, Feb 17, 2011 at 4:10 PM, pstatham wrote: >> Hi Guys, >> >> I've installed the cx_Oracle module for Python and I'm trying to >> connect to my remote Oracle db. Like so (username, password and ip >> below aren't real don't worry) >> >>>>> uid = "scott" >>>>> pwd = "tiger" >>>>> service = "10.5.1.12:1521:PR10" >>>>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) >> >> This however gives me the following error: >> >> Traceback (most recent call last): >> ?File "", line 1, in >> cx_Oracle.DatabaseError: ORA-12545: Connect failed because target host >> or object >> ?does not exist >> >> I've also tried the following (jdbc string which works fine for java) >> >>>>> service = "jdbc:oracle:thin:@10.5.1.12:1521:PR10" >>>>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) >> Traceback (most recent call last): >> ?File "", line 1, in >> cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect >> identifier >> ?specified >> >> I'm not sure what's going on because I know that the ip, port and >> service name. are correct? And as I said I can connect to it via JDBC >> in Java. >> >> Any ideas? >> >> Thanks, >> Paul >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > From anurag.chourasia at gmail.com Thu Feb 17 10:09:04 2011 From: anurag.chourasia at gmail.com (Anurag Chourasia) Date: Thu, 17 Feb 2011 20:39:04 +0530 Subject: Connecting to remote Oracle db via Python In-Reply-To: References: <1e4f8836-20ff-4317-8c30-047ef6ec0c71@4g2000yqo.googlegroups.com> <3E14881B2E2442D1BD9E842223F00791@SEFASBRISTOL> <2F802216565E44489600A03F763219A8010BAD46@mia.SEFASBRISTOL> Message-ID: Apart from that, you could also use a shorter format which is a correction over what you were trying with earlier. Here...... uid = "scott" pwd = "tiger" service = "//10.5.1.12:1521/PR10" db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) Please let us know how it goes. Regards, Anurag On Thu, Feb 17, 2011 at 8:28 PM, Anurag Chourasia wrote: > Try this please and it should work. > > Connection_String = > 'scott/tiger@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.1.12)(PORT=1521)))(CONNECT_DATA=(SID=PR10)))' > > db = cx_Oracle.connect(Connection_String) > > I'm sorry i missed a bracket there. > > Regards, > Anurag > > > On Thu, Feb 17, 2011 at 8:18 PM, Paul Statham wrote: >> Doesn't seem to work >> >> -----Original Message----- >> From: Anurag Chourasia [mailto:anurag.chourasia at gmail.com] >> Sent: 17 February 2011 14:41 >> To: Paul Statham >> Cc: python-list at python.org >> Subject: Re: Connecting to remote Oracle db via Python >> >> Could you try by using a connecting string in the standard format as below? >> >> Connection_String = >> 'scott/tiger@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.1.12(PORT=1521)))(CONNECT_DATA=(SID=PR10)))' >> >> db = cx_Oracle.connect(Connection_String) >> >> Regards, >> Anurag >> >> On Thu, Feb 17, 2011 at 4:10 PM, pstatham wrote: >>> Hi Guys, >>> >>> I've installed the cx_Oracle module for Python and I'm trying to >>> connect to my remote Oracle db. Like so (username, password and ip >>> below aren't real don't worry) >>> >>>>>> uid = "scott" >>>>>> pwd = "tiger" >>>>>> service = "10.5.1.12:1521:PR10" >>>>>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) >>> >>> This however gives me the following error: >>> >>> Traceback (most recent call last): >>> ?File "", line 1, in >>> cx_Oracle.DatabaseError: ORA-12545: Connect failed because target host >>> or object >>> ?does not exist >>> >>> I've also tried the following (jdbc string which works fine for java) >>> >>>>>> service = "jdbc:oracle:thin:@10.5.1.12:1521:PR10" >>>>>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) >>> Traceback (most recent call last): >>> ?File "", line 1, in >>> cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect >>> identifier >>> ?specified >>> >>> I'm not sure what's going on because I know that the ip, port and >>> service name. are correct? And as I said I can connect to it via JDBC >>> in Java. >>> >>> Any ideas? >>> >>> Thanks, >>> Paul >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> >> > From andrea.crotti.0 at gmail.com Thu Feb 17 10:14:00 2011 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 17 Feb 2011 16:14:00 +0100 Subject: interfacing python with emacs In-Reply-To: References: Message-ID: Not ready yet but the structure of the python and elisp files is more or less there: git://github.com/AndreaCrotti/empathy.git Feel welcome for any comments/hints. About the communication between the processes I think I'll use stdin/out too, since it comes quite natural using emacs sub-processes. At the moment I'm only reading a line at a time, but probably I should send an EOF somehow from the emacs side, and then I could simply use read() every time on stdin. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Thu Feb 17 10:17:53 2011 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 17 Feb 2011 16:17:53 +0100 Subject: First time using an API... In-Reply-To: References: Message-ID: 2011/2/17 Matty Sarro > This may be kind of a stupid question, so please be gentle. > I've only ever used most programming in the past when shell scripting > couldn't handle what I needed done. So, I rarely dabble with things > like API's, or even python-isms. I just program to get things done. > > Well, that's about to change :) > I am in charge of deploying a platform to allow people across my > company to access a variety of crunched metrics using splunk. I need > to allow access into the data using Splunk's RESTful API, which is > implemented in both java and python. The thing is, I have no idea how > to do that. I've looked through some of the documentation, and it has > me start a pydoc server on the system but when i navigate to the page > it just shows listings of functions. The descriptions would be great, > except they don't really tell me a lot. For instance, nothing really > seems to say "fetchRecord(user_name) fetches all records matching a > particular user name". Further, how do I actually use the API? > > I appreciate any of the pointers you can offer. Its a big part of this > project, but my minor knowledge in programming isn't helping me much > here. > -Matty > -- > http://mail.python.org/mailman/listinfo/python-list Well things are not always (almost never) documented as you would like. A suggestion I can give is to use ipython and play with the modules. Pass something in and see what you get. And better yet write some unit tests to see if the functions do what you expect they do. If the API is not completely dumb you should understand quickly how to use it. Also some other code that uses that library might be useful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From santiago.caracol at gmail.com Thu Feb 17 10:23:47 2011 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Thu, 17 Feb 2011 07:23:47 -0800 (PST) Subject: reimport module every n seconds Message-ID: <6cde71c6-5c56-40ea-9849-50fc44e5decc@o14g2000prb.googlegroups.com> Hello, a server program of mine uses data which are compiled to a Python module for efficiency reasons. In some module of the server program I import the data: from data import data As the data often changes, I would like to reimport it every n (e.g. 10) seconds. Unfortunately, it is rather difficult and probably not a good idea to manipulate the main function of the server program, as it comes from Django. (Already asked in the Django newsgroup, but I got no answer there.) Is there a way to do the reimport in a module that is used by the main program? Santiago From rbotting at csusb.edu Thu Feb 17 10:29:25 2011 From: rbotting at csusb.edu (RJB) Date: Thu, 17 Feb 2011 07:29:25 -0800 (PST) Subject: Another related OO Python ? References: <6849fd3f-5116-4b35-b274-dc76ae39f777@a11g2000pro.googlegroups.com> Message-ID: On Feb 16, 6:21?am, Eric Brunel wrote: > In article > <6849fd3f-5116-4b35-b274-dc76ae39f... at a11g2000pro.googlegroups.com>, > > > > > > ?RJB wrote: > > On Feb 16, 12:48?am, Eric Brunel > > wrote: > > > In article , > > > ?Doug Epling wrote: > > > > > hey, does anyone find the UML useful during Python development of larger > > > > projects? > > > > Well, UML being very Java/C++ oriented, I found out that Python idioms > > > were really difficult to represent in the diagrams. So I'm using it to a > > > very small extent and for documentation only, just to give an idea about > > > how classes are organized. For the rest, and IMHO, it's really too > > > impractical to be of any use. > > > Which of the 13 diagrams have tried and rejected?-) > > Diagrams that aren't too bound to the language like e.g the deployment > diagram can still be used, of course. I was mainly talking about the > class diagram, which is still the central point of a model. But I even > found sequence diagrams quite hard to write for Python, unless they are > very simplistic ones. Yes. Especially if you draw interactions with a tool and make them tidy. I believe in very rough and rapid sketches in pencil or chalk. Complex code either needs rethinking or in the worst case an activity diagram, IMHO. Of course doing the diagrams by hand after the code is OK .... How do you justify the time spent doing it? From gsowww at yahoo.co.uk Thu Feb 17 10:32:21 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 15:32:21 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: > I'm having a awfully hard time figuring out why a home CCTV > application might need privilege at all. ?Are you sure you really need > privilege? ?It sounds to me like there may be some larger design > issues mandating the need for privilege when it's not really > necessary. > A user login should only able to view the footage. It's important that a user login cannot delete any images/video. This much can be done with ACL - but having said that a user login would still be able to copy the images/video, so ACL would work but is not ideal - I could prevent copying with raised privileges. If I were to allow a user to archive footage without using an admin login then that would require ACL with write access, which is out of the question. If a camera loses its connection I think it's OK to let a user restart the camera without using gksu, but this would require raised privileges. There are other misc. points where I need write access. The directory where images are stored by the live feed can become 'messy' (for want of a better way of putting it), write access is needed to tidy it up before live camera images can be viewed, it's not really appropriate to use gksu here every time a user wants to view the live images. Also (I don't know exactly how I'm going to do this yet) but I'm thinking I might use the system log functions (syslogd) as part of a scheme to ensure the integrity of saved footage and the archive. As a misc. point, I'm wondering why redhat 6 hasn't included gksu in with its gnome, policykit is there, but gksu is at this point omitted. (The policykit widget is not included with pygtk, or at least the version I'm using.) There is a package from another repo (beesu) that is a gksu replacement, but it's not ideal to be rummaging around in all corners of the Internet for code as critical as this. From jeanmichel at sequans.com Thu Feb 17 10:33:59 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 17 Feb 2011 16:33:59 +0100 Subject: reimport module every n seconds In-Reply-To: <6cde71c6-5c56-40ea-9849-50fc44e5decc@o14g2000prb.googlegroups.com> References: <6cde71c6-5c56-40ea-9849-50fc44e5decc@o14g2000prb.googlegroups.com> Message-ID: <4D5D3FE7.3080209@sequans.com> Santiago Caracol wrote: > Hello, > > a server program of mine uses data which are compiled to a Python > module for efficiency reasons. In some module of the server program I > import the data: > > from data import data > > As the data often changes, I would like to reimport it every n (e.g. > 10) seconds. > > Unfortunately, it is rather difficult and probably not a good idea to > manipulate the main function of the server program, as it comes from > Django. (Already asked in the Django newsgroup, but I got no answer > there.) Is there a way to do the reimport in a module that is used by > the main program? > > Santiago > import data def getUpdate(): reload(data) return data.data JM WARNING : there's a lot to know about reload, the main thing is that it cannot properly reimport a module in a sense that all objects already created from that module are not impacted. You can search this archive if you want to know more as this subject has already been discussed many times. From python at mrabarnett.plus.com Thu Feb 17 10:56:00 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 17 Feb 2011 15:56:00 +0000 Subject: return an object of a different class In-Reply-To: <1297953588.4951.1.camel@localhost.localdomain> References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> <1297953588.4951.1.camel@localhost.localdomain> Message-ID: <4D5D4510.3030402@mrabarnett.plus.com> On 17/02/2011 14:39, Westley Mart?nez wrote: > On Thu, 2011-02-17 at 11:43 +0000, Steven D'Aprano wrote: >> On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote: >> >>> Karim wrote: >>>> [snip] >>>>> If you don't want to use a factory function I believe you can do this: >>>>> >>>>> class MyNumber(object): >>>>> def __new__(cls, n): >>>>> if n<= 100: >>>>> cls = SmallNumbers >>>>> else: >>>>> cls = BigNumbers >>>>> return object.__new__(cls, n) >>>>> ... >>>>> >>>>> Chard. >>>> >>>> Very beautiful code great alternative to factory method! To memorize >>>> this pythonic way. >>>> >>>> Regards >>>> Karim >>> Do you think that the MyNumber constructor returning something else >>> than a MyNumber instance is the pythonic way ? It would rather be the >>> cryptonic way ! (haha) >> >> >> Support for constructors returning something other than an instance of >> the class is not an accident, it is a deliberate, and useful, design. The >> Fine Manual says: >> >> object.__new__(cls[, ...]) >> >> Called to create a new instance of class cls. [...] >> The return value of __new__() should be the new object >> instance (usually an instance of cls). >> [...] >> If __new__() does not return an instance of cls, then >> the new instance?s __init__() method will not be invoked. >> >> >> http://docs.python.org/reference/datamodel.html#basic-customization >> >> So while it is *usual* for the constructor to return an instance of the >> class, it's not compulsory, and returning other types is explicitly >> supported. >> >> To answer your question about whether this is Pythonic... here's a small >> clue from Python 2.5: >> >>>>> n = int("4294967296") # 2**32 >>>>> type(n) >> >> >> >> >> So, yes, absolutely, it is not only allowed for class constructors to >> return an instance of a different class, but there is precedence in the >> built-ins. >> >> >> >> -- >> Steven > Python 3 removed longs because they were ... cryptonic! > Strictly speaking, they weren't removed. ints were removed and long was renamed int. From jtim.arnold at gmail.com Thu Feb 17 11:14:36 2011 From: jtim.arnold at gmail.com (Tim) Date: Thu, 17 Feb 2011 08:14:36 -0800 (PST) Subject: client server socket interaction (inetd) Message-ID: Hi, I have an inetd service on freebsd that calls a program (daemon.py) with which I want the remote user to communicate. I can call daemon.py from the command line on the host machine and it works fine. What I don't understand is how to make my remote client script actually communicate. If I'm understanding correctly, the code below just takes a message and sends it to inetd and writes the stdout from the process to the client. How can I modify the code to send a response back? Here's the outline of what I want to do: (1) client sends the message to the server (client -> inetd -> daemon.py), (2) client receives output back from the server, (3) client user responds to a question from the remote process (4) client continues to receive output back. where 2-3-4 happen as needed by the remote process. Cries out for a while loop doesn't it? I just don't know what to put in it. Currently I just have steps 1 and 2 working. Client sends one message and gets all output back. If server asks a question, processes deadlock with server waiting and client unable to respond. thanks, --Tim Arnold # imports, constants set #def line_buffer(sock): # code to yield the string response in # blocks of 1024 bytes def client(ip,port,message): sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect((ip,port)) sock.send(message) for line in line_buffer(sock): print line sock.close() if __name__ == '__main__': message = ' '.join(sys.argv[1:]) ) print 'working... %s %s' % (SERVER_IP,SERVER_PORT) client(SERVER_IP,SERVER_PORT,message) print 'done.' From andrea.crotti.0 at gmail.com Thu Feb 17 11:44:15 2011 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 17 Feb 2011 17:44:15 +0100 Subject: where to import Message-ID: Suppose I have a function which uses a few external libraries, and this function is only called once every 10 executions. Does it make sense to import these libraries for the whole module? import sys def fun(): import x, y, z Something like this is acceptable/good practice in the scenario I was talking about? Does it make any difference for performances too? -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Thu Feb 17 11:47:33 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 17 Feb 2011 08:47:33 -0800 Subject: client server socket interaction (inetd) In-Reply-To: References: Message-ID: On Thu, Feb 17, 2011 at 8:14 AM, Tim wrote: > Hi, I have an inetd service on freebsd that calls a program > (daemon.py) with which I want the remote user to communicate. I can > call daemon.py from the command line on the host machine and it works > fine. > > What I don't understand is how to make my remote client script > actually communicate. If I'm understanding correctly, the code below > just takes a message and sends it to inetd and writes the stdout from > the process to the client. > > How can I modify the code to send a response back? Here's the > outline of what I want to do: > (1) client sends the message to the server (client -> inetd -> > daemon.py), > (2) client receives output back from the server, > (3) client user responds to a question from the remote process > (4) client continues to receive output back. > > where 2-3-4 happen as needed by the remote process. Cries out for a > while loop doesn't it? I just don't know what to put in it. Currently > I just have steps 1 and 2 working. Client sends one message and gets > all output back. If server asks a question, processes deadlock with > server waiting and client unable to respond. > thanks, > --Tim Arnold > > # imports, constants set > #def line_buffer(sock): > # code to yield the string response in > # blocks of 1024 bytes > > def client(ip,port,message): > sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > sock.connect((ip,port)) > sock.send(message) > for line in line_buffer(sock): > print line > sock.close() > > if __name__ == '__main__': > message = ' '.join(sys.argv[1:]) ) > print 'working... %s %s' % (SERVER_IP,SERVER_PORT) > client(SERVER_IP,SERVER_PORT,message) > print 'done.' You could probably use strace/truss/ktrace to see what each process has done so far. I wonder if your server process needs to flush its output when writing the prompt? It might help us help you if you post the server code as well. Also, the client code above doesn't appear to be complete... posting more of that might help us help you as well. Specifically: does line_buffer() know when to stop doing its thing? BTW, when using unbuffered sockets, things are a bit complex - 3 writes in the server may appear as 1 recv or 4 recv's (or about any other #, including 3) in the client. Usually you'll get 3, but that's not fully reliable. Sometimes it helps to wrap up your socket in a python file, or to use something like http://stromberg.dnsalias.org/~strombrg/bufsock.html HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Feb 17 12:06:26 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 17 Feb 2011 09:06:26 -0800 Subject: where to import In-Reply-To: References: Message-ID: On Thu, Feb 17, 2011 at 8:44 AM, andrea crotti wrote: > Suppose I have a function which uses a few external libraries, > and this function is only called once every 10 executions. > > Does it make sense to import these libraries for the whole module? Yes. Having all the imports in one place keeps the code organized and makes figuring out dependencies easier. Also, IIRC, importing something within a function can lead to problems if threads are involved. Further, it's just plain conventional. PEP 8 (the Python style guide) states: "Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants." > import sys > > def fun(): > ??? import x, y, z > > Something like this is acceptable/good practice in the scenario I was > talking about? I would argue no, per PEP 8. > Does it make any difference for performances too? Yes, of course. Importing a module multiple times (as would happen if fun() is called multiple times) is obviously slower than just importing it once, although the 2nd and subsequent imports will be faster as Python will just return another reference to the previously imported instance of the module rather than importing it again from scratch. There are also local variable vs. module-global variable speed differences involved. However, "Premature optimization is the root of all evil." Have you checked whether the imports are taking a significant amount of execution time? Odds are that they aren't. When optimizing, do so on the basis of empirical data; run your program under a profiler, and let the results guide your optimization process. Cheers, Chris -- http://blog.rebertia.com From tjhanson at yahoo.com Thu Feb 17 12:11:49 2011 From: tjhanson at yahoo.com (Tim Hanson) Date: Thu, 17 Feb 2011 09:11:49 -0800 Subject: another problem with modules Message-ID: <201102170911.49585.tjhanson@yahoo.com> Okay, I solved my problem with Python finding modules: I put the following into a file in my home directory, on the good advice of Andrea Crotti: import sys sys.path.append('/home/foo/mypath' I named the file "~/pypath.py", so now, in idle: import pypath No errors. I'm still getting a little frustrated loading modules. I typed the following little test function into idle: def intersect(seq1,seq2): res=[] for x in seq1: if x in seq2: res.append(x) return res intersect('spam','spmmer') No big deal. Runs fine. Exited and re-entered idle, import pypath import intersect #the name of a file that contains the above short function. intersect('spam','spmmer') Traceback (most recent call last): File "", line 1, in intersect('spam','spmmer') TypeError: 'module' object is not callable >>> Huh? Why doesn't this run when imported? More importantly, how do I interpret this error message so that I can find the problem myself next time? From fmarshallxremove_the_x at acm.org Thu Feb 17 12:24:05 2011 From: fmarshallxremove_the_x at acm.org (Fred Marshall) Date: Thu, 17 Feb 2011 09:24:05 -0800 Subject: wxPython in Eclipse? Message-ID: How do I use wxPython or wxGlade in the context of Eclipse? A link to a howto would be great! Thanks, Fred From robert.kern at gmail.com Thu Feb 17 12:26:22 2011 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 17 Feb 2011 11:26:22 -0600 Subject: another problem with modules In-Reply-To: <201102170911.49585.tjhanson@yahoo.com> References: <201102170911.49585.tjhanson@yahoo.com> Message-ID: On 2/17/11 11:11 AM, Tim Hanson wrote: > import pypath > import intersect #the name of a file that contains the above short function. > intersect('spam','spmmer') > > Traceback (most recent call last): > File "", line 1, in > intersect('spam','spmmer') > TypeError: 'module' object is not callable >>>> > > Huh? Why doesn't this run when imported? More importantly, how do I > interpret this error message so that I can find the problem myself next time? Please read the first section of this page about modules in the tutorial: http://docs.python.org/tutorial/modules.html#modules -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andrea.crotti.0 at gmail.com Thu Feb 17 12:27:17 2011 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 17 Feb 2011 18:27:17 +0100 Subject: where to import In-Reply-To: References: Message-ID: 2011/2/17 Chris Rebert > Yes, of course. Importing a module multiple times (as would happen if > fun() is called multiple times) is obviously slower than just > importing it once, although the 2nd and subsequent imports will be > faster as Python will just return another reference to the previously > imported instance of the module rather than importing it again from > scratch. There are also local variable vs. module-global variable > speed differences involved. > > However, "Premature optimization is the root of all evil." Have you > checked whether the imports are taking a significant amount of > execution time? Odds are that they aren't. When optimizing, do so on > the basis of empirical data; run your program under a profiler, and > let the results guide your optimization process. > > Cheers, > Chris > -- > http://blog.rebertia.com Well no I wasn't really worried about performances. I just thought that if an external module is really almost never used, it might make sense to import it only when it's really needed. Anyway if it's against the holy pep8 then it's fine :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet.digitig at spamgourmet.com Thu Feb 17 12:33:43 2011 From: usenet.digitig at spamgourmet.com (usenet.digitig at spamgourmet.com) Date: Thu, 17 Feb 2011 11:33:43 -0600 Subject: Suggested editor for wxPython on Ubuntu Message-ID: Ok, I've decided that Boa Constructor is too buggy to be useful under Ubuntu, so what would the team recommend for developing Python projects with wxPython? Preferably with some GUI design capability? From python at mrabarnett.plus.com Thu Feb 17 12:44:57 2011 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 17 Feb 2011 17:44:57 +0000 Subject: another problem with modules In-Reply-To: <201102170911.49585.tjhanson@yahoo.com> References: <201102170911.49585.tjhanson@yahoo.com> Message-ID: <4D5D5E99.7040908@mrabarnett.plus.com> On 17/02/2011 17:11, Tim Hanson wrote: > Okay, I solved my problem with Python finding modules: > > I put the following into a file in my home directory, on the good advice of > Andrea Crotti: > > import sys > sys.path.append('/home/foo/mypath' > > I named the file "~/pypath.py", so now, in idle: > > import pypath > > No errors. > > I'm still getting a little frustrated loading modules. I typed the following > little test function into idle: > > def intersect(seq1,seq2): > res=[] > for x in seq1: > if x in seq2: > res.append(x) > return res > > intersect('spam','spmmer') > > > No big deal. Runs fine. Exited and re-entered idle, > > import pypath > import intersect #the name of a file that contains the above short function. This imports the module 'intersect'. The name 'intersect' refers to the module itself. > intersect('spam','spmmer') This tries to call the module. Perhaps you meant: intersect.intersect('spam','spmmer') If you have a module "foo", which contains a function "bar", then "foo" refers to the module and "foo.bar" refers to the function. > > Traceback (most recent call last): > File "", line 1, in > intersect('spam','spmmer') > TypeError: 'module' object is not callable >>>> > > Huh? Why doesn't this run when imported? More importantly, how do I > interpret this error message so that I can find the problem myself next time? From tjreedy at udel.edu Thu Feb 17 12:45:27 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 Feb 2011 12:45:27 -0500 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: On 2/17/2011 10:32 AM, GSO wrote: >> I'm having a awfully hard time figuring out why a home CCTV >> application might need privilege at all. Are you sure you really need >> privilege? It sounds to me like there may be some larger design >> issues mandating the need for privilege when it's not really >> necessary. >> > > A user login should only able to view the footage. It's important > that a user login cannot delete any images/video. This much can be > done with ACL - but having said that a user login would still be able > to copy the images/video, so ACL would work but is not ideal - I could > prevent copying with raised privileges. If I were to allow a user to > archive footage without using an admin login then that would require > ACL with write access, which is out of the question. > > If a camera loses its connection I think it's OK to let a user restart > the camera without using gksu, but this would require raised > privileges. > > There are other misc. points where I need write access. The directory > where images are stored by the live feed can become 'messy' (for want > of a better way of putting it), write access is needed to tidy it up > before live camera images can be viewed, Could restarts and cleanups be done with a root daemon separate from user scripts? FWIW, I recently read an article about how some internet-connected cameras are much more accessible to the world than the owners probably intended, even to the point, sometimes, of providing access to the built-in gui control panel. So some thought seems appropriate in this area ;-). -- Terry Jan Reedy From tjreedy at udel.edu Thu Feb 17 12:53:10 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 Feb 2011 12:53:10 -0500 Subject: First time using an API... In-Reply-To: References: Message-ID: On 2/17/2011 10:17 AM, andrea crotti wrote: > > > 2011/2/17 Matty Sarro > > > This may be kind of a stupid question, so please be gentle. > I've only ever used most programming in the past when shell scripting > couldn't handle what I needed done. So, I rarely dabble with things > like API's, or even python-isms. I just program to get things done. > > Well, that's about to change :) > I am in charge of deploying a platform to allow people across my > company to access a variety of crunched metrics using splunk. I need > to allow access into the data using Splunk's RESTful API, which is > implemented in both java and python. The thing is, I have no idea how > to do that. I've looked through some of the documentation, and it has > me start a pydoc server on the system but when i navigate to the page > it just shows listings of functions. The descriptions would be great, > except they don't really tell me a lot. For instance, nothing really > seems to say "fetchRecord(user_name) fetches all records matching a > particular user name". Further, how do I actually use the API? > > I appreciate any of the pointers you can offer. Its a big part of this > project, but my minor knowledge in programming isn't helping me much > here. > -Matty > -- > http://mail.python.org/mailman/listinfo/python-list > > Well things are not always (almost never) documented as you would like. > A suggestion I can give is to use ipython and play with the modules. > Pass something in and see what you get. > > And better yet write some unit tests to see if the functions do what you > expect they do. > If the API is not completely dumb you should understand quickly how to > use it. > > Also some other code that uses that library might be useful. What would also help is a toy database small enough so you can calculate by hand what answers you expect to get. -- Terry Jan Reedy From detlev at die-offenbachs.de Thu Feb 17 13:00:24 2011 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Thu, 17 Feb 2011 19:00:24 +0100 Subject: Editor/IDE with Python coverage support? References: Message-ID: Matt Chaput wrote: > Are there any editors/IDEs with good support for line-coloring from > Python test coverage results? (I normally use Eclipse + PyDev but > PyDev's current coverage support isn't much better than nothing.) > > Thanks, > > Matt eric4 (Python2) and eric5 (Python3) do have this support (and much much more). See http://eric-ide.python-projects.org for details. Detlev -- Detlev Offenbach detlev at die-offenbachs.de From aahz at pythoncraft.com Thu Feb 17 13:05:13 2011 From: aahz at pythoncraft.com (Aahz) Date: 17 Feb 2011 10:05:13 -0800 Subject: reimport module every n seconds References: <6cde71c6-5c56-40ea-9849-50fc44e5decc@o14g2000prb.googlegroups.com> Message-ID: In article <6cde71c6-5c56-40ea-9849-50fc44e5decc at o14g2000prb.googlegroups.com>, Santiago Caracol wrote: > >a server program of mine uses data which are compiled to a Python >module for efficiency reasons. In some module of the server program I >import the data: > >from data import data > >As the data often changes, I would like to reimport it every n (e.g. >10) seconds. Don't do that. ;-) I suggest using exec instead. However, I would be surprised if import worked faster than, say, JSON (more precisely, I doubt that it's enough faster to warrnat this kludge). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational science. Most reasoning about it is at best rationalization of gut feelings, and at worst plain wrong." --GvR, python-ideas, 2009-03-01 From roy at panix.com Thu Feb 17 13:14:22 2011 From: roy at panix.com (Roy Smith) Date: Thu, 17 Feb 2011 13:14:22 -0500 Subject: reimport module every n seconds References: <6cde71c6-5c56-40ea-9849-50fc44e5decc@o14g2000prb.googlegroups.com> Message-ID: In article , aahz at pythoncraft.com (Aahz) wrote: > In article > <6cde71c6-5c56-40ea-9849-50fc44e5decc at o14g2000prb.googlegroups.com>, > Santiago Caracol wrote: > > > >a server program of mine uses data which are compiled to a Python > >module for efficiency reasons. In some module of the server program I > >import the data: > > > >from data import data > > > >As the data often changes, I would like to reimport it every n (e.g. > >10) seconds. > > Don't do that. ;-) I suggest using exec instead. However, I would be > surprised if import worked faster than, say, JSON (more precisely, I > doubt that it's enough faster to warrnat this kludge). I'm with Aahz. Don't do that. I don't know what you're doing, but I suspect an even better solution would be to have your program run a "reconfigure" thread which listens on a UDP socket and reads a JSON object from it. Or, at the very least, which listens for a signal which kicks it to re-read some JSON from a disk file. This will be more responsive when the data changes quickly and more efficient when it changes slowly. As opposed to just polling for changes every 10 seconds. From cousinstanley at gmail.com Thu Feb 17 13:19:29 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 17 Feb 2011 18:19:29 +0000 (UTC) Subject: First time using an API... References: Message-ID: Matty Sarro wrote: > .... > I am in charge of deploying a platform to allow people > across my company to access a variety of crunched metrics > using splunk. > .... For the convenience of others that may not be familar with splunk .... http://en.wikipedia.org/wiki/Splunk http://www.splunk.com/ -- Stanley C. Kitching Human Being Phoenix, Arizona From cousinstanley at gmail.com Thu Feb 17 13:27:04 2011 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 17 Feb 2011 18:27:04 +0000 (UTC) Subject: Suggested editor for wxPython on Ubuntu References: Message-ID: usenet.digitig at spamgourmet.com wrote: > Ok, I've decided that Boa Constructor is too buggy to be useful > under Ubuntu, so what would the team recommend for developing > Python projects with wxPython? Preferably with some GUI design capability? perhaps .... python-wxglade GUI designer written in Python with wxPython wxGlade is a GUI designer written in Python with the popular GUI toolkit wxPython, that helps you create wxWidgets/wxPython user interfaces. At the moment it can generate Python, C++ and XRC (wxWidgets' XML resources) code. -- Stanley C. Kitching Human Being Phoenix, Arizona From msarro at gmail.com Thu Feb 17 13:33:54 2011 From: msarro at gmail.com (Matty Sarro) Date: Thu, 17 Feb 2011 13:33:54 -0500 Subject: First time using an API... In-Reply-To: References: Message-ID: Good point, pardon the assumption :) I'm reading more about RESTful and it looks like its a web based API. Oh well, I'll figure it out, I mean, my job depends on it, lol. On Thu, Feb 17, 2011 at 1:19 PM, Cousin Stanley wrote: > > Matty Sarro wrote: > >> .... >> I am in charge of deploying a platform to allow people >> across my company to access a variety of crunched metrics >> using splunk. >> .... > > ?For the convenience of others > ?that may not be familar with splunk .... > > ? ?http://en.wikipedia.org/wiki/Splunk > > ? ?http://www.splunk.com/ > > > -- > Stanley C. Kitching > Human Being > Phoenix, Arizona > > -- > http://mail.python.org/mailman/listinfo/python-list > From askutt at gmail.com Thu Feb 17 13:39:56 2011 From: askutt at gmail.com (Adam Skutt) Date: Thu, 17 Feb 2011 10:39:56 -0800 (PST) Subject: Best way to gain root privileges References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: On Feb 17, 10:32?am, GSO wrote: > > I'm having a awfully hard time figuring out why a home CCTV > > application might need privilege at all. ?Are you sure you really need > > privilege? ?It sounds to me like there may be some larger design > > issues mandating the need for privilege when it's not really > > necessary. > > A user login should only able to view the footage. ?It's important > that a user login cannot delete any images/video. ?This much can be > done with ACL - but having said that a user login would still be able > to copy the images/video, so ACL would work but is not ideal - I could > prevent copying with raised privileges. No, you can't. If I can read the data, I can copy the data. How did you think you were going to prevent copying? Remember that copying is just read()/write() in a loop. > If I were to allow a user to > archive footage without using an admin login then that would require > ACL with write access, which is out of the question. > > If a camera loses its connection I think it's OK to let a user restart > the camera without using gksu, but this would require raised > privileges. > > There are other misc. points where I need write access. ?The directory > where images are stored by the live feed can become 'messy' (for want > of a better way of putting it), write access is needed to tidy it up > before live camera images can be viewed, it's not really appropriate > to use gksu here every time a user wants to view the live images. > Also (I don't know exactly how I'm going to do this yet) but I'm > thinking I might use the system log functions (syslogd) as part of a > scheme to ensure the integrity of saved footage and the archive. > As Terry suggests (and I fully concur), all of these issues are best solved by having a privileged daemon (though it may not need to be root or entirely root). Inter-process communication, if necessary, can be handled by UNIX domain sockets. There are then a few ways to validate the privileges of the users connecting to the sockets: * UNIX sockets support passing credentials across the socket for privilege checks. This is however somewhat non-portable (different platforms do it differently), and I'd imagine a minor PITA in the Python. * Create sockets with different ownership/permissions and then require the users to be in the correct UNIX group. Note that the permissions of the sockets themselves are ignored on some platforms, so each socket needs to be in a directory with the correct permissions and ownership set: /var/run/cctvd/admin/ <--- cctv:cctvadmin 750 /var/run/cctvd/admin/socket <--- Doesn't matter, so 777 cctv:cctvadmin is fine /var/run/cctvd/user/ <---- cctv:cctv 750 (or cctvuser for the group, if you'd rather) /var/run/cctvd/user/socket <--- Doesn't matter, so 777 cctv:cctv Though these days it may be overkill, you may be able to rely on the socket write permission (the others don't matter) and user/group for protection. You can also do actual authentication, but that's another huge can of worms best left undisturbed if possible. * It also allows you to simply stream the files over the sockets instead of the client accessing the files directly. Your call, though. Done properly, there's a high probability the only thing that needs to run as root is the init script. You may also need startup code that runs as root (not setuid root) that handles daemonization, opens anything that must be open as root, and then drops root privileges. Lots of daemons do this, so you can find examples out there on how to accomplish this. There are also utilities that can handle this for you, which may be adequate in your situation. Privilege separation can be used so that a bug in handling the user socket doesn't accidentally grant someone admin and/or root privileges (basically, have separate processes with separate privileges). There are examples out there of how to achieve this for various purposes as well. As a rule, when you find yourself needing privilege escalation, you should go back and see if there is another way to achieve what you want. There's a good chance the other way will be a better way. It sounds to me like you need to better define all the operations that your software needs to be able to accomplish and what privileges are necessary to accomplish each operation. Once you've defined that, it should become much easier to build a design that properly handles each operation without the need for privilege escalation. Adam From alister.ware at ntlworld.com Thu Feb 17 13:40:16 2011 From: alister.ware at ntlworld.com (Alister Ware) Date: Thu, 17 Feb 2011 18:40:16 GMT Subject: Newbie getting desperate with for References: Message-ID: On Thu, 17 Feb 2011 16:42:05 +0800, Werner wrote: > On 17/02/11 16:39, Chris Rebert wrote: >> On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: >>> I have a trivially simple piece of code called timewaster.py: >>> ____________________________________________________ >>> >>> while True: >>> i = 0 >>> for i in range(10): >>> break >>> _____________________________________________________ >>> >>> It runs fine with Eric but when I try to run it from shell... >>>> ./timewaster.py >>> ./timewaster.py: line 4: syntax error near unexpected token `(' >>> ./timewaster.py: line 4: ` for i in range(10):' >>> >>> I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python >>> version 2.6.5, both show the above. >>> >>> Before I tear out my hair any more (only 3 left) I thought I'd ask >>> here what I am doing wrong. >> >> Looks like it's being run as a shell script rather than through the >> Python interpreter (hence why the error is not in the form of an >> exception with a traceback). >> >> Try adding: >> >> #!/usr/bin/env python >> >> as the first line in your file. This tells the shell to run the script >> using Python. >> >> Or alternatively, instead of: >> >> ./timewaster.py >> >> use: >> >> python timewaster.py >> >> which likewise explicitly invokes the Python interpreter. >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > Yes, that was it. AYAA! > > Thank you very much. may I ask what is the purpose of this code segment, it does not look like it would achieve much? -- All that glitters is not gold; all that wander are not lost. From tdldev at gmail.com Thu Feb 17 13:58:56 2011 From: tdldev at gmail.com (Verde Denim) Date: Thu, 17 Feb 2011 13:58:56 -0500 Subject: Suggested editor for wxPython on Ubuntu In-Reply-To: References: Message-ID: On Thu, Feb 17, 2011 at 1:27 PM, Cousin Stanley wrote: > > usenet.digitig at spamgourmet.com wrote: > > > Ok, I've decided that Boa Constructor is too buggy to be useful > > under Ubuntu, so what would the team recommend for developing > > Python projects with wxPython? Preferably with some GUI design > capability? > > perhaps .... python-wxglade > > GUI designer written in Python with wxPython > > wxGlade is a GUI designer written in Python with the popular > GUI toolkit wxPython, that helps you create wxWidgets/wxPython > user interfaces. At the moment it can generate Python, C++ and > XRC (wxWidgets' XML resources) code. > > Although I do use wx-glade, geany, pycrust, netbeans, gedit, and vi, I found and purchased WingIDE a while back. For the cost, it has nearly everything I've seen in Netbeans for Java. I believe a license is about $80(USD) and is well worth the money (at least to me). Runs on win, lin, and mac. The auto-complete and function/method/lib/package helpers are invaluable to me since I haven't memorized everything within the python libs. - Jack > > -- > Stanley C. Kitching > Human Being > Phoenix, Arizona > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at address-in-sig.invalid Thu Feb 17 14:41:07 2011 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 17 Feb 2011 19:41:07 +0000 (UTC) Subject: client server socket interaction (inetd) References: Message-ID: On Thu, 17 Feb 2011 08:14:36 -0800, Tim wrote: > Hi, I have an inetd service on freebsd that calls a program (daemon.py) > with which I want the remote user to communicate. I can call daemon.py > from the command line on the host machine and it works fine. > > What I don't understand is how to make my remote client script actually > communicate. If I'm understanding correctly, the code below just takes a > message and sends it to inetd and writes the stdout from the process to > the client. > > How can I modify the code to send a response back? > The code you've shown would appear to be doing what you've specified, though only you can know whether this is what you intended. Each time you run the client it: - connects to the server - sends a request - reads the response(s) - closes the socket and exits. If you run it a second time it should do the same again. Is this the case? An inetd server should be started when a connection request is received. It should read requests, sending a response to each request in turn, until the connection is closed, when it will be stopped by inetd. Without seeing the code for the server and the corresponding inetd configuration line its not possible to say more. BTW, I prefer xinetd to inetd - its configuration is much more modular and easier to understand. If freebsd supports xinetd it may make life easier if you use it rather than inetd. Here's the outline > of what I want to do: > (1) client sends the message to the server (client -> inetd -> > daemon.py), > (2) client receives output back from the server, (3) client user > responds to a question from the remote process (4) client continues to > receive output back. > > where 2-3-4 happen as needed by the remote process. Cries out for a > while loop doesn't it? I just don't know what to put in it. Currently I > just have steps 1 and 2 working. Client sends one message and gets all > output back. If server asks a question, processes deadlock with server > waiting and client unable to respond. thanks, > --Tim Arnold > > # imports, constants set > #def line_buffer(sock): > # code to yield the string response in # blocks of 1024 bytes > > def client(ip,port,message): > sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > sock.connect((ip,port)) > sock.send(message) > for line in line_buffer(sock): > print line > sock.close() > > if __name__ == '__main__': > message = ' '.join(sys.argv[1:]) ) > print 'working... %s %s' % (SERVER_IP,SERVER_PORT) > client(SERVER_IP,SERVER_PORT,message) print 'done.' -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From katie at coderstack.co.uk Thu Feb 17 14:44:20 2011 From: katie at coderstack.co.uk (Katie T) Date: Thu, 17 Feb 2011 19:44:20 +0000 Subject: Best way to gain root privileges In-Reply-To: References: Message-ID: On Wed, Feb 16, 2011 at 9:26 PM, GSO wrote: > I'm sure this question is as old as time, but what is the best way to > gain root privileges? ?(Am using Python 2.6.5, pygtk2 v2.16, Gtk > v2.18.9, on RHEL6.) > Running any kind of script sudo'd is a bad idea, it's very very hard (in many cases impossible) to do securely. Root permissions in general should only be used for what they're needed for and nothing else (that means getting the permission, doing the stuff that needs to be done as root, and then returning back to normal privs), anything else is just asking for trouble. Katine -- CoderStack http://www.coderstack.co.uk/php-jobs The Software Developer Job Board From cefp at inf.elte.hu Thu Feb 17 15:24:58 2011 From: cefp at inf.elte.hu (CEFP Summer School) Date: Thu, 17 Feb 2011 21:24:58 +0100 Subject: CEFP 2011 Summer School: call for participation Message-ID: <4D5D841A.2090606@inf.elte.hu> ===================================== 4TH CENTRAL EUROPEAN FUNCTIONAL PROGRAMMING SCHOOL (CEFP 2011) EOTVOS LORAND UNIVERSITY, BUDAPEST, HUNGARY June 14-24, 2011 http://plc.inf.elte.hu/cefp THE REGISTRATION IS OPEN! ===================================== SCOPE OF THE SUMMER SCHOOL The Central-European Functional Programming School is an intensive summer school in the field of functional programming. The invited lecturers are the most prominent researchers in the field in Europe, and they will present state-of-the-art functional programming techniques: * Andrew Butterfield (University of Dublin, Ireland): Reasoning about I/O in functional programs * Clemens Grelck (University of Amsterdam, The Netherlands): Multicore SAC * Johan Jeuring (Utrecht University, The Netherlands): Strategies for learning functional programming * Rita Loogen (Philipps University Marburg, Germany): Eden * Simon Marlow (Microsoft Research, United Kingdom): Distributed Haskell * Greg Michaelson (Heriot-Watt University Edinburgh, Scotland): Box Calculus * Rinus Plasmeijer (Radboud University Nijmegen, The Netherlands): Defining distributed GUI applications with iTasks * Kostis Sagonas (University of Athens, Greece): Multicore Erlang * Mary Sheeran (Chalmers University of Technology, Sweden): Feldspar: Implementation and Application AIMS OF THE SUMMER SCHOOL The main goal of the summer school is to bring together computer scientists, researchers, graduate and PhD students. The programme of the summer school includes: * In depth lectures about a selected number of recently emerged advanced functional programming techniques, taught by experts in the field. * Practical exercises accompanying the lectures to be solved by the students at the school. These exercises guide the students' learning to a great extent. A high quality lab is available at the school site. * Team work is stimulated, such that the students can also learn from each other. * Forum for PhD students. The CEFP school provides a forum for PhD students to present their research results as part of the workshop programme. Abstract submission is before the summer school, full paper version after the summer school. Selected and reviewed papers will be published in the LNCS Volume of the revised lectures. *** IMPORTANT: THE DEADLINE FOR THE ABSTRACTS IS APRIL 30, 2011 *** LOCATION The event is organized and hosted by the Department of Programming Languages and Compilers, Faculty of Informatics, E?tv?s Lor?nd University, Budapest, Hungary. Budapest is the capital of Hungary with nearly 2.000.000 inhabitants. It is divided into two parts by the river Danube. There are nine bridges over the river which connect the two sides. The most beautiful ones are Chain Bridge (L?nch?d), Elisabeth Bridge (Erzs?bet h?d) and Liberty Bridge (Szabads?g h?d). One of the best places to walk around is the Castle District. There is a breath-taking view of the city from the Fisherman's Bastion. Across from the Fisherman's Bastion is Matthias Church named after the Hungarian King Matthias. In the Castle District you can find the S?ndor Palace, the residence and workplace of the Head of the State. Budapest is richly endowed with natural springs of thermal waters possessing various medicinal properties (Gell?rt Baths and Hotel, Sz?chenyi Baths, Luk?cs Medicinal Baths etc.). The largest building in the country is the building of the Hungarian Parliament, which is situated on the bank of the Danube. The Neo-Gothic building complex was built between 1884 and 1904 according to the plans of Imre Steindl. There are many other sights in Budapest, just like Heroes? Square, St. Stephen?s Basilica, Andr?ssy Avenue, Margaret-island, Gell?rt Hill and the Citadell etc. For more information about Budapest, please visit the http://www.budapestinfo.hu/ home page. INFORMATION The registration fee is EUR 410. The registration fee does not include the price of the accommodation! For more information please visit our website where you can find more details about the CEFP 2011 School and the programme. Our website is: http://plc.inf.elte.hu/cefp From icanbob at gmail.com Thu Feb 17 15:47:07 2011 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 17 Feb 2011 12:47:07 -0800 (PST) Subject: client server socket interaction (inetd) References: Message-ID: On Feb 17, 2:41 pm, Martin Gregorie wrote: > On Thu, 17 Feb 2011 08:14:36 -0800, Tim wrote: > > Hi, I have an inetd service on freebsd that calls a program (daemon.py) > > with which I want the remote user to communicate. I can call daemon.py > > from the command line on the host machine and it works fine. > > > What I don't understand is how to make my remote client script actually > > communicate. If I'm understanding correctly, the code below just takes a > > message and sends it to inetd and writes the stdout from the process to > > the client. > > > How can I modify the code to send a response back? > > The code you've shown would appear to be doing what you've specified, > though only you can know whether this is what you intended. > Each time you run the client it: > - connects to the server > - sends a request > - reads the response(s) > - closes the socket and exits. > > If you run it a second time it should do the same again. Is this the case? > > An inetd server should be started when a connection request is received. > It should read requests, sending a response to each request in turn, > until the connection is closed, when it will be stopped by inetd. > > Without seeing the code for the server and the corresponding inetd > configuration line its not possible to say more. > > BTW, I prefer xinetd to inetd - its configuration is much more modular > and easier to understand. If freebsd supports xinetd it may make life > easier if you use it rather than inetd. > > Here's the outline > > > > > of what I want to do: > > (1) client sends the message to the server (client -> inetd -> > > daemon.py), > > (2) client receives output back from the server, (3) client user > > responds to a question from the remote process (4) client continues to > > receive output back. > > > where 2-3-4 happen as needed by the remote process. Cries out for a > > while loop doesn't it? I just don't know what to put in it. Currently I > > just have steps 1 and 2 working. Client sends one message and gets all > > output back. If server asks a question, processes deadlock with server > > waiting and client unable to respond. thanks, > > --Tim Arnold > > > # imports, constants set > > #def line_buffer(sock): > > # code to yield the string response in # blocks of 1024 bytes > > > def client(ip,port,message): > > sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > > sock.connect((ip,port)) > > sock.send(message) > > for line in line_buffer(sock): > > print line > > sock.close() > > > if __name__ == '__main__': > > message = ' '.join(sys.argv[1:]) ) > > print 'working... %s %s' % (SERVER_IP,SERVER_PORT) > > client(SERVER_IP,SERVER_PORT,message) print 'done.' > > -- > martin@ | Martin Gregorie > gregorie. | Essex, UK > org | Have a look at the SIMPL toolkit (http://www.icanprogram.com/06py/ lesson1/lesson1.html). It will allow you to do exactly what you want without having to dive into socket programming. bob From andrea.crotti.0 at gmail.com Thu Feb 17 15:55:36 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 17 Feb 2011 21:55:36 +0100 Subject: interfacing python with emacs In-Reply-To: References: Message-ID: Il giorno 17/feb/2011, alle ore 16.14, andrea crotti ha scritto: > Not ready yet but the structure of the python and elisp files is more or less there: > git://github.com/AndreaCrotti/empathy.git > > Feel welcome for any comments/hints. > > About the communication between the processes I think I'll use stdin/out too, since it comes quite natural using emacs sub-processes. > > At the moment I'm only reading a line at a time, but probably I should send an EOF somehow from the emacs side, and then I could simply use read() every time on stdin. Changed name due to a clash (and before I didn't give the right url) https://github.com/AndreaCrotti/empity I'll update news here whenever it's really testable. Quick question, is it correct to load dynamically modules like this? def handle_load(self, mod): try: info = imp.find_module(mod) except ImportError: self.send("module not found") else: imp.load_module(mod, *info) And in the "imp" module it says " This module provides the components needed to build your own __import__ function. Undocumented functions are obsolete." Isn't there a better way (a warning when called) to inform that something is obsolete? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jtim.arnold at gmail.com Thu Feb 17 16:02:08 2011 From: jtim.arnold at gmail.com (Tim) Date: Thu, 17 Feb 2011 13:02:08 -0800 (PST) Subject: client server socket interaction (inetd) References: Message-ID: <2bbf94d0-7929-478d-a9c7-2e18de540945@i39g2000prd.googlegroups.com> On Feb 17, 2:41?pm, Martin Gregorie wrote: > On Thu, 17 Feb 2011 08:14:36 -0800, Tim wrote: > > Hi, I have an inetd service on freebsd that calls a program (daemon.py) > > with which I want the remote user to communicate. ?I can call daemon.py > > from the command line on the host machine and it works fine. > > > What I don't understand is how to make my remote client script actually > > communicate. If I'm understanding correctly, the code below just takes a > > message and sends it to inetd and writes the stdout from the process to > > the client. > > > How can I modify the code to send a response back? > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | Thanks Martin, you're right: > Each time you run the client it: > - connects to the server > - sends a request > - reads the response(s) > - closes the socket and exits. that is exactly what it's doing. But. The server may encounter a problem during the process and ask the user for more information like 'abort/retry' or something like that. What my code does *not* do is allow the user to respond to such a mid- process question (so the server can take in that information and proceed with its process). The server can ask, but there's no mechanism for the user to respond to a question. > Without seeing the code for the server and the corresponding inetd > configuration line its not possible to say more. I'm not trying to be opaque, but the reason I left out the code for the server (daemon.py) is that it works as expected when exec'd from the command line. That is, the process begins, asks a question, gets an answer and continues. The inetd configuration is: myservice stream tcp nowait root /local/daemon.py daemon.py From tjreedy at udel.edu Thu Feb 17 16:31:56 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 Feb 2011 16:31:56 -0500 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: On 2/17/2011 1:39 PM, Adam Skutt wrote: > On Feb 17, 10:32 am, GSO wrote: >>> I'm having a awfully hard time figuring out why a home CCTV >>> application might need privilege at all. Are you sure you really need >>> privilege? It sounds to me like there may be some larger design >>> issues mandating the need for privilege when it's not really >>> necessary. >> >> A user login should only able to view the footage. It's important >> that a user login cannot delete any images/video. This much can be >> done with ACL - but having said that a user login would still be able >> to copy the images/video, so ACL would work but is not ideal - I could >> prevent copying with raised privileges. > > No, you can't. If I can read the data, I can copy the data. How did > you think you were going to prevent copying? Remember that copying is > just read()/write() in a loop. > >> If I were to allow a user to >> archive footage without using an admin login then that would require >> ACL with write access, which is out of the question. >> >> If a camera loses its connection I think it's OK to let a user restart >> the camera without using gksu, but this would require raised >> privileges. >> >> There are other misc. points where I need write access. The directory >> where images are stored by the live feed can become 'messy' (for want >> of a better way of putting it), write access is needed to tidy it up >> before live camera images can be viewed, it's not really appropriate >> to use gksu here every time a user wants to view the live images. >> Also (I don't know exactly how I'm going to do this yet) but I'm >> thinking I might use the system log functions (syslogd) as part of a >> scheme to ensure the integrity of saved footage and the archive. >> > > As Terry suggests (and I fully concur), all of these issues are best > solved by having a privileged daemon (though it may not need to be > root or entirely root). Come to think of it, I would first consider creating a 'cctv' user that owns the cameras and storage directories, and files and only do anything as root if absolutely necessary. -- Terry Jan Reedy From cs at zip.com.au Thu Feb 17 16:40:37 2011 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 18 Feb 2011 08:40:37 +1100 Subject: Newbie getting desperate with for In-Reply-To: References: Message-ID: <20110217214037.GA25438@cskk.homeip.net> On 17Feb2011 18:40, Alister Ware wrote: | On Thu, 17 Feb 2011 16:42:05 +0800, Werner wrote: | | > On 17/02/11 16:39, Chris Rebert wrote: | >> On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: | >>> I have a trivially simple piece of code called timewaster.py: | >>> ____________________________________________________ | >>> while True: [...] | >>> It runs fine with Eric but when I try to run it from shell... | >>>> ./timewaster.py | >>> ./timewaster.py: line 4: syntax error near unexpected token `(' | >>> ./timewaster.py: line 4: ` for i in range(10):' [...] | >> Looks like it's being run as a shell script rather than through the | >> Python interpreter (hence why the error is not in the form of an | >> exception with a traceback). | >> | >> Try adding: | >> #!/usr/bin/env python | >> | >> as the first line in your file. This tells the shell to run the script | >> using Python. [...] | may I ask what is the purpose of this code segment, it does not look like | it would achieve much? When you run a command from the shell, it first tries to directly execv() it, which calls the kernel to load and execute the file. If the file is not a kernel compatibly file, the shell then presumes the file is a shell script and interprets it as shell commands. Thus the original error message, since it is Python code and not shell code. The shebang line: #!/usr/bin/env python is a special piece of script syntax recognised _by_the_kernel_, which makes the script something the kernel will handle. If a file's first two characters are: #! then the kernel reads the remainder of that line as a command to be used to execute the script by appending the script pathname. So the line supplied causes the kernel to execute the command: /usr/bin/env python the-path-to-the-script ... where "..." would be any additional arguments you supplied on the command line. In this way, many scripting languages can be "directly" executed. These two characters were chosen because "#" is a comment character in many/most UNIX scripting languages and because "!" is the traditional UNIX indicator for a "shell escape" it tools like editors, where one indicates that one wants to run an external shell comand by preceeding it with a "!" "(bang"), eg: ! ls and variations. Now, it is usual to provide the direct path to the interpreter, eg: #!/bin/sh #!/usr/bin/python etc. However, some some things that path may vary from system to system. On POSIX systems, /bin/sh is guarenteed to be present at that location, but python or perl may be in /usr/bin or /usr/local/bin etc. The #! syntax _requires_ an absolute path to the executable. If the executable may be in different places (because the script author is shipping a script that will run on some unknown system) this is a problem. The "env" command is actually a special hook for setting environment variables before running a command, but without extra arguments is can be used to rely on $PATH to find the command. So the command: /usr/bin/env python incantation finds "the python that would normally be run", without needing to know the install path of the python executable. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A common criticism of the Internet is that it is dominated by the crude, the uninformed, the immature, the smug, the untalented, the repetitious, the pathetic, the hostile, the deluded, the self-righteous, and the shrill. This criticism overlooks the fact that the Internet also offers -- for the savvy individual who knows where to look -- the tasteless and the borderline insane. - _A brief History of Computing #12_ Heck From grahn+nntp at snipabacken.se Thu Feb 17 16:44:20 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 17 Feb 2011 21:44:20 GMT Subject: How to use Python well? References: Message-ID: On Wed, 2011-02-16, snorble wrote: > I use Python a lot, but not well. I usually start by writing a small > script, no classes or modules. Then I add more content to the loops, > and repeat. It's a bit of a trial and error learning phase, making > sure I'm using the third party modules correctly, and so on. I end up > with a working script, but by the end it looks messy, unorganized, and > feels hacked together. I feel like in order to reuse it or expand it > in the future, I need to take what I learned and rewrite it from > scratch. > > If I peeked over a Python expert's shoulder while they developed > something new, how would their habits differ? Do they start with > classes from the start? > > I guess I'm looking for something similar to "Large Scale C++ Software > Design" for Python. Or even just a walkthrough of someone competent > writing something from scratch. I'm not necessarily looking for a > finished product that is well written. I'm more interested in, "I have > an idea for a script/program, and here is how I get from point A to > point B." > > Or maybe I'm looking for is best practices for how to organize the > structure of a Python program. I love Python and I just want to be > able to use it well. Good questions -- and you got some really good answers already! What I always do when starting a program is: - Split it into a 'if __name__ == "__main__":' which does the command-line parsing, usage message and so on; and a function which contains the logic, i.e. works like the program would have if the OS had fed it its arguments as Python types - Document functions and classes. - Avoid having functions use 'print' and 'sys.std*', in case I need to use them with other files. I pass file-like objects as arguments instead. - Write user documentation and build/installation scripts. Since I'm on Unix, that means man pages and a Makefile. And that's all in the normal case. No need to do anything more fancy if it turns out I'll never have to touch that program again. I use classes when I see a use for them. The "see" part comes from quite a few years' worth of experience with object-oriented design in Python and C++ ... not sure how to learn that without getting lost in Design with a capital 'D' for a few years ... Anyway, I don't feel bad if I don't find any classes at first. /Jorgen -- // Jorgen Grahn O o . From tjreedy at udel.edu Thu Feb 17 16:45:48 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 17 Feb 2011 16:45:48 -0500 Subject: where to import In-Reply-To: References: Message-ID: On 2/17/2011 12:27 PM, andrea crotti wrote: > Well no I wasn't really worried about performances. > I just thought that if an external module is really almost never used, > it might make sense to import it only when it's really needed. If the module is only used in one function and the function may called 0 or 1 times, them yes, it makes some sense. But as soon as the function is called multiple times, or the module is used in more than one function, or someone wants to quickly look at the file to determine its dependencies, then local imports become more trouble than they are worth. For instance, suppose a new maintainer adds a function to the module that needs something from another module. If all imports are at the top, then it is trivial to see what imports are already made and whether they need modification. I believe the stdlib used to have some local imports, and might still, for all I know. PEP 8 is is based on long-term experience with the multi-maintainer stdlib as well as some stylistic preferences. -- Terry Jan Reedy From smersh009x at gmail.com Thu Feb 17 16:46:14 2011 From: smersh009x at gmail.com (SMERSH009) Date: Thu, 17 Feb 2011 13:46:14 -0800 (PST) Subject: Converting getCSS Count Code from java to python References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> Message-ID: On Feb 2, 7:03?am, Duncan Booth wrote: > Stefan Behnel wrote: > > You are using Selenium RC here. I have no idea if there is a Python > > API to it or what that API looks like. The rest is just trivial code > > that you can map 1:1 to Python: > > > ? ? ?def count_css_matches(css_locator): > > ? ? ? ? ?java_script_code = ''' > > ? ? ? ? ? ? ?var cssMatches = eval_css("%s", window.document); > > ? ? ? ? ? ? ?cssMatches.length;''' % css_locator > > ? ? ? ? ?return int(selenium.getEval(java_script_code)) > > > Although I'd simplify the JavaScript code somewhat to make it a plain > > expression. > > You also need somewhere: > > ? ? from selenium import selenium > > and in Python the method that is needed is selenium.get_eval(...) > > -- > Duncan Boothhttp://kupuguy.blogspot.com On Feb 2, 7:03 am, Duncan Booth wrote: > Stefan Behnel wrote: > > You are using Selenium RC here. I have no idea if there is a Python > > API to it or what that API looks like. The rest is just trivial code > > that you can map 1:1 to Python: > > > def count_css_matches(css_locator): > > java_script_code = ''' > > var cssMatches = eval_css("%s", window.document); > > cssMatches.length;''' % css_locator > > return int(selenium.getEval(java_script_code)) > > > Although I'd simplify the JavaScript code somewhat to make it a plain > > expression. > > You also need somewhere: > > from selenium import selenium > > and in Python the method that is needed is selenium.get_eval(...) > > -- > Duncan Boothhttp://kupuguy.blogspot.com Hi All, Thanks a lot for the help. I feel like I've made some progress, yet I am still stuck with the following error when I try to print self.count_css_matches('css=[id="listGuests"]') I've also included the Selenium code below. Any further help would be appreciated. Traceback (most recent call last): File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line 27, in test_untitled print self.count_css_matches('css=[id="listGuests"]') File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line 17, in count_css_matches return int(selenium.get_eval(self, java_script_code)) TypeError: unbound method get_eval() must be called with selenium instance as first argument (got Untitled instance instead) ---------------------------------------------------------------------- from selenium import selenium import unittest, time from datetime import datetime class Untitled(unittest.TestCase): def count_css_matches(self, css_locator): java_script_code = ''' var cssMatches = eval_css("%s", window.document); cssMatches.length;''' % css_locator return int(selenium.get_eval(self, java_script_code)) #return int(selenium.getEval(java_script_code)) def setUp(self): self.verificationErrors = [] self.selenium = selenium("localhost", 4445, "*chrome", "http:// www.guestlistnation.com/") self.selenium.start() def test_untitled(self): sel = self.selenium sel.window_maximize() sel.open("/Events.aspx?Location=SAN FRANCISCO") sel.click("css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails']") sel.wait_for_page_to_load("30000") print self.count_css_matches('css=[id="listGuests"]') if __name__ == "__main__": unittest.main() From steve+comp.lang.python at pearwood.info Thu Feb 17 16:46:58 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Feb 2011 21:46:58 GMT Subject: Best way to gain root privileges References: Message-ID: <4d5d9752$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Feb 2011 19:44:20 +0000, Katie T wrote: > Running any kind of script sudo'd is a bad idea, it's very very hard (in > many cases impossible) to do securely. Root permissions in general > should only be used for what they're needed for and nothing else (that > means getting the permission, doing the stuff that needs to be done as > root, and then returning back to normal privs), anything else is just > asking for trouble. I agree with your general point, but the specific point to avoid running scripts with sudo? Are you sure you're not conflating sudo with setuid? By my reading, sudo is far preferred over running scripts setuid root. Linux, for example, simply will not run scripts setuid root because of the security risk, while running things using sudo is considered best practice, and much preferred over logging in as root. The idea of sudo is to do exactly what you say: doing the stuff needed as root with elevated permission, then returning to normal. -- Steven From gsowww at yahoo.co.uk Thu Feb 17 16:54:33 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 21:54:33 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: > > Could restarts and cleanups be done with a root daemon separate from user > scripts? > I like the idea of a user creating a login as you do typically with client/server progs, no need to have the root password all the time: http://www.python.org/dev/peps/pep-3143/ http://pypi.python.org/pypi/python-daemon http://docs.python.org/library/multiprocessing.html#module-multiprocessing http://docs.python.org/library/socket.html > FWIW, I recently read an article about how some internet-connected cameras > are much more accessible to the world than the owners probably intended, > even to the point, sometimes, of providing access to the built-in gui > control panel. So some thought seems appropriate in this area ;-). I'd like to read that article. ?My experience of wifi is that if you are not using the latest encryption standards then it will be hacked quite quickly. ?Otherwise if the product is cheap then I think you need to take a good look at the software running on it. ?I wouldn't put any CCTV anywhere near an Internet connected Windows machine (not unless someone at least in the first instance can tell me how to install the security updates without getting hacked first!). ?I've been looking at this type of (wired) product myself http://j.mp/gLycNf (the starting point for supported devices is here http://linuxtv.org/wiki/index.php/Hardware_Device_Information ). At the end of the day it's a dodgy business connecting any home CCTV to a network - I'll fork out on a dedicated system if I need to essentially, but Redhat 6 'seems' (I'm sure I'd soon know if it wasn't) secure, and so it's not a priority (they are expensive). Computers are hacked in 2 ways, local crime will prefer to intrude and get direct access to the keyboard, but if you have your home CCTV installed then that does quite effectively keep them out, so the CCTV software keeps itself secure. ?As to hacking over the Internet, I've found on a security hardened Redhat install, it seems the browser (don't run flash - use a kiosk login for this, e.g., xguest http://j.mp/eGKL19 ) can still be hacked and with hacking of the computer's memory following possibly also, but nothing that has got through to the core of the operating system as yet, so the CCTV software (I hope! you usually can tell) is safe -- I've just reminded myself to put the browser in a virtual machine at some point :) From grahn+nntp at snipabacken.se Thu Feb 17 16:55:05 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 17 Feb 2011 21:55:05 GMT Subject: Archiving Modules References: <9a340d80-ddfd-4985-8b2c-1e4a14e953a9@w21g2000yqm.googlegroups.com> Message-ID: On Wed, 2011-02-16, peter wrote: > I am writing a small Tkinter utility to control archive files in > multiple formats (mainly for my own amusement and education). > Basically it presents the user with two adjacent listboxes, one with > the contents of the target directory and one with the contents of the > archive. By clicking buttons labelled '<' and '>' the user can copy > files to and from the archive. The actual archiving functionality > derives from the modules zipfile and tarfile. > > It all seems to be working fine, but I have two residual queries. > Firstly for the sake of completeness I would like to include .rar > archives, but there doesn't seem to be an equivalent rarfile module. > I use both Windows and Linux on various machines, so need a cross > platform solution which does not depend on external modules. The only > one I have found is at http://pypi.python.org/pypi/rarfile/1.0, but it > seems this does rely on an external module. Is there anything out > there? RAR is a proprietary format, which complicates things. For example, Linux distributions like Debian cannot distribute software which handles it. If Python included such a module, they'd be forced to remove it from their version. I wouldn't encourage its use by writing /more/ software which handles it. IMHO, archives should be widely readable forever, and to be that they need to be in a widely used, open format. /Jorgen -- // Jorgen Grahn O o . From gsowww at yahoo.co.uk Thu Feb 17 17:01:31 2011 From: gsowww at yahoo.co.uk (GSO) Date: Thu, 17 Feb 2011 22:01:31 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: > Come to think of it, I would first consider creating a 'cctv' user that owns > the cameras and storage directories, and files and only do anything as root > if absolutely necessary. > You can run 'sudo -g [group] ...', so no need to go near root. > > Running any kind of script sudo'd is a bad idea, it's very very hard > (in many cases impossible) to do securely. Root permissions in general > should only be used for what they're needed for and nothing else (that > means getting the permission, doing the stuff that needs to be done as > root, and then returning back to normal privs), anything else is just > asking for trouble. > If you can do what you need to do with a dedicated group for the task/program (as above) then hopefully this would not be such an insecure approach? Better than asking for the admin. login possibly also? From santoso.wijaya at gmail.com Thu Feb 17 17:12:10 2011 From: santoso.wijaya at gmail.com (Santoso Wijaya) Date: Thu, 17 Feb 2011 14:12:10 -0800 Subject: where to import In-Reply-To: References: Message-ID: As a general rule, I group all my imports in the beginning of the module's source, even if it is only used a handful of times by a few functions. However, on such cases as the import is only needed by specific function(s) zero or once, then I do the import in the function itself. Importing argparse, for example: import sys def api_func(*args, **kwargs): pass def main(args): import argparse # ... api_func() if __name__ == '__main__': sys.exit(main(sys.argv)) ~/santa ~/santa On Thu, Feb 17, 2011 at 1:45 PM, Terry Reedy wrote: > On 2/17/2011 12:27 PM, andrea crotti wrote: > > Well no I wasn't really worried about performances. >> I just thought that if an external module is really almost never used, >> it might make sense to import it only when it's really needed. >> > > If the module is only used in one function and the function may called 0 or > 1 times, them yes, it makes some sense. But as soon as the function is > called multiple times, or the module is used in more than one function, or > someone wants to quickly look at the file to determine its dependencies, > then local imports become more trouble than they are worth. > > For instance, suppose a new maintainer adds a function to the module that > needs something from another module. If all imports are at the top, then it > is trivial to see what imports are already made and whether they need > modification. > > I believe the stdlib used to have some local imports, and might still, for > all I know. PEP 8 is is based on long-term experience with the > multi-maintainer stdlib as well as some stylistic preferences. > > -- > Terry Jan Reedy > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Thu Feb 17 17:24:31 2011 From: roy at panix.com (Roy Smith) Date: Thu, 17 Feb 2011 17:24:31 -0500 Subject: How to use Python well? References: Message-ID: In article , Jorgen Grahn wrote: > - Write user documentation and build/installation scripts. Since I'm > on Unix, that means man pages and a Makefile. Wow, I haven't built a man page in eons. These days, user documentation for me means good help text for argparse to use. If I need something more than that, I'll write it up in our wiki. > Anyway, I don't feel bad if I don't find any classes at first. Same here. I don't usually find a reason to refactor things into classes until I've written the second or third line of code :-) Somewhat more seriously, the big clue for me that I've got a class hiding in there is when I start having all sorts of globals. That's usually a sign you've done something wrong. From torriem at gmail.com Thu Feb 17 17:55:19 2011 From: torriem at gmail.com (Michael Torrie) Date: Thu, 17 Feb 2011 15:55:19 -0700 Subject: How to use Python well? In-Reply-To: <4d5c5712$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4d5c5712$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D5DA757.2070609@gmail.com> On 02/16/2011 04:00 PM, Steven D'Aprano wrote: > You should read about bottom-up and top-down programming. You'll probably > end up doing some of both, but mostly top-down. Most of my development is done by designing top-down and then coding bottom-up. Coding top down is fine, but I'd expect to refactor the code frequently as I try to spin code off into standalone modules. From martin at address-in-sig.invalid Thu Feb 17 18:09:13 2011 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Thu, 17 Feb 2011 23:09:13 +0000 (UTC) Subject: client server socket interaction (inetd) References: <2bbf94d0-7929-478d-a9c7-2e18de540945@i39g2000prd.googlegroups.com> Message-ID: On Thu, 17 Feb 2011 13:02:08 -0800, Tim wrote: > But. The server may encounter a problem > during the process and ask the user for more information like > 'abort/retry' or something like that. > Servers never ask the client for information: they are strictly request/ response handlers. To do what you're asking about, you'll need to change both the client and server: - the client must analyse every response and, if necessary, ask for more input from the user. IMO it would be best to design it so it can accept several commands, with 'quit' being one of them. Either that or all request/response pairs must be designed so that the client can always send a single request, output the result and exit no matter what the server returns. - the server must always return a response to every possible request or log a failure reason, preferably to the system log which is /var/log/messages in Linux, and die. The server must thoroughly validate requests and return an adequate error message if errors were found. I'd strongly suggest that every request generates a single (newline terminated?) response message because that makes error detection much easier. If the response is multi-line, send it as a single line, possibly as a comma-separated list, and let the client format it for display I tend to precede every request and response message with a fixed length byte count: this way the recipient process always knows how many bytes to read and can report errors if the received length is wrong. Using an 'end of message marker' (NEWLINE unless a message can legally contain internal newlines) can also be useful. I tend to put an error flag in the response message because this simplifies the client. I also design all messages to be plain ASCII because this makes debugging a lot easier. If things really turn to worms you can use wireshark to watch the traffic and read it straight off the screen without needing to decode binary values, etc. So, an invalid request and response might look like this: Request: "0013,WHOIS,elvis\n" Response: "0030,ERROR,Unknown request: WHOIS\n" > The inetd configuration is: > myservice stream tcp nowait root /local/daemon.py daemon.py > >From what I recall about inetd that should be OK - I guess it must be since you can get one request through, and I assume (you didn't say) that a second request is also accepted without restarting the server. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From wdahn at netfront.net Thu Feb 17 18:10:28 2011 From: wdahn at netfront.net (Werner) Date: Fri, 18 Feb 2011 07:10:28 +0800 Subject: Newbie getting desperate with for In-Reply-To: References: Message-ID: On 18/02/11 02:40, Alister Ware wrote: > On Thu, 17 Feb 2011 16:42:05 +0800, Werner wrote: > >> On 17/02/11 16:39, Chris Rebert wrote: >>> On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: >>>> I have a trivially simple piece of code called timewaster.py: >>>> ____________________________________________________ >>>> >>>> while True: >>>> i = 0 >>>> for i in range(10): >>>> break >>>> _____________________________________________________ >>>> >>>> It runs fine with Eric but when I try to run it from shell... >>>>> ./timewaster.py >>>> ./timewaster.py: line 4: syntax error near unexpected token `(' >>>> ./timewaster.py: line 4: ` for i in range(10):' >>>> >>>> I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python >>>> version 2.6.5, both show the above. >>>> >>>> Before I tear out my hair any more (only 3 left) I thought I'd ask >>>> here what I am doing wrong. >>> >>> Looks like it's being run as a shell script rather than through the >>> Python interpreter (hence why the error is not in the form of an >>> exception with a traceback). >>> >>> Try adding: >>> >>> #!/usr/bin/env python >>> >>> as the first line in your file. This tells the shell to run the script >>> using Python. >>> >>> Or alternatively, instead of: >>> >>> ./timewaster.py >>> >>> use: >>> >>> python timewaster.py >>> >>> which likewise explicitly invokes the Python interpreter. >>> >>> Cheers, >>> Chris >>> -- >>> http://blog.rebertia.com >> >> Yes, that was it. AYAA! >> >> Thank you very much. > > may I ask what is the purpose of this code segment, it does not look like > it would achieve much? > > > > It is meant to put load on a CPU, RAM and disk (swap). The code now looks like this: #!/usr/bin/python while True: i = 0 for i in range(20000000): break I needed this to get an idea how virtual machines inside a host perform when you run a few instances of it. The objective was at what point responsiveness gets severely degraded by load. To measure that I used __________________________________ #!/usr/bin/python import time def time_it(threshold , period): t0 = time.time() # daytime at start of period time.sleep(period) t1 = time.time() # daytime at end of period t2 = t1-t0 # calculate actual lenght of period # subtract how long it should have been t3 =(t2 - period) *1000 if t3>=threshold: # if the differnce is too high report it print time.strftime('%Y/%m/%d %H:%M:%S ') , round(t3, 2), "ms" while True: time_it(5.0, 0.1) ___________________________________ Not very sophisticated but it gave me a few clues of what I'm interested in. Regards Werner Dahn From matt at sidefx.com Thu Feb 17 18:28:46 2011 From: matt at sidefx.com (Matt Chaput) Date: Thu, 17 Feb 2011 18:28:46 -0500 Subject: Unit testing multiprocessing code on Windows Message-ID: <4D5DAF2E.4090909@sidefx.com> Does anyone know the "right" way to write a unit test for code that uses multiprocessing on Windows? The problem is that with both "python setup.py tests" and "nosetests", when they get to a multiprocessing test they spawn multiple copies of the testing suite. The test runner in PyDev works properly. Maybe multiprocessing is starting new Windows processes by copying the command line of the current process, but if the command line is "nosetests", it's a one way ticket to an infinite explosion of processes. Any thoughts? Thanks, Matt From cs at zip.com.au Thu Feb 17 18:29:21 2011 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 18 Feb 2011 10:29:21 +1100 Subject: Newbie getting desperate with for In-Reply-To: <20110217214037.GA25438@cskk.homeip.net> References: <20110217214037.GA25438@cskk.homeip.net> Message-ID: <20110217232921.GA18261@cskk.homeip.net> On 18Feb2011 08:40, I wrote: | On 17Feb2011 18:40, Alister Ware wrote: | | On Thu, 17 Feb 2011 16:42:05 +0800, Werner wrote: | | > On 17/02/11 16:39, Chris Rebert wrote: | | >> On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: | | >>> I have a trivially simple piece of code called timewaster.py: | | >>> ____________________________________________________ | | >>> while True: | [...] | | may I ask what is the purpose of this code segment, it does not look like | | it would achieve much? [... long shebang description...] Hmm, looks like maybe you meant the original python snippet. If so, my apologies for the long misanswer. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I was gratified to be able to answer promptly and I did. I said I didn't know. - Mark Twain From matt at whoosh.ca Thu Feb 17 18:31:59 2011 From: matt at whoosh.ca (Matt Chaput) Date: Thu, 17 Feb 2011 18:31:59 -0500 Subject: Unit testing multiprocessing code on Windows Message-ID: <4D5DAFEF.8080205@whoosh.ca> Does anyone know the "right" way to write a unit test for code that uses multiprocessing on Windows? The problem is that with both "python setup.py tests" and "nosetests", when they get to testing any code that starts Processes they spawn multiple copies of the testing suite (i.e. the new processes start running tests as if they were started with "python setup.py tests"/"nosetests"). The test runner in PyDev works properly. Maybe multiprocessing is starting new Windows processes by copying the command line of the current process? But if the command line is "nosetests", it's a one way ticket to an infinite explosion of processes. Any thoughts? Thanks, Matt From anikom15 at gmail.com Thu Feb 17 18:53:14 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 17 Feb 2011 15:53:14 -0800 Subject: return an object of a different class In-Reply-To: <4D5D4510.3030402@mrabarnett.plus.com> References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> <1297953588.4951.1.camel@localhost.localdomain> <4D5D4510.3030402@mrabarnett.plus.com> Message-ID: <1297986794.2494.0.camel@localhost.localdomain> On Thu, 2011-02-17 at 15:56 +0000, MRAB wrote: > On 17/02/2011 14:39, Westley Mart?nez wrote: > > On Thu, 2011-02-17 at 11:43 +0000, Steven D'Aprano wrote: > >> On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote: > >> > >>> Karim wrote: > >>>> [snip] > >>>>> If you don't want to use a factory function I believe you can do this: > >>>>> > >>>>> class MyNumber(object): > >>>>> def __new__(cls, n): > >>>>> if n<= 100: > >>>>> cls = SmallNumbers > >>>>> else: > >>>>> cls = BigNumbers > >>>>> return object.__new__(cls, n) > >>>>> ... > >>>>> > >>>>> Chard. > >>>> > >>>> Very beautiful code great alternative to factory method! To memorize > >>>> this pythonic way. > >>>> > >>>> Regards > >>>> Karim > >>> Do you think that the MyNumber constructor returning something else > >>> than a MyNumber instance is the pythonic way ? It would rather be the > >>> cryptonic way ! (haha) > >> > >> > >> Support for constructors returning something other than an instance of > >> the class is not an accident, it is a deliberate, and useful, design. The > >> Fine Manual says: > >> > >> object.__new__(cls[, ...]) > >> > >> Called to create a new instance of class cls. [...] > >> The return value of __new__() should be the new object > >> instance (usually an instance of cls). > >> [...] > >> If __new__() does not return an instance of cls, then > >> the new instance?s __init__() method will not be invoked. > >> > >> > >> http://docs.python.org/reference/datamodel.html#basic-customization > >> > >> So while it is *usual* for the constructor to return an instance of the > >> class, it's not compulsory, and returning other types is explicitly > >> supported. > >> > >> To answer your question about whether this is Pythonic... here's a small > >> clue from Python 2.5: > >> > >>>>> n = int("4294967296") # 2**32 > >>>>> type(n) > >> > >> > >> > >> > >> So, yes, absolutely, it is not only allowed for class constructors to > >> return an instance of a different class, but there is precedence in the > >> built-ins. > >> > >> > >> > >> -- > >> Steven > > Python 3 removed longs because they were ... cryptonic! > > > Strictly speaking, they weren't removed. ints were removed and long was > renamed int. My point stands. From philip at semanchuk.com Thu Feb 17 20:22:37 2011 From: philip at semanchuk.com (philip at semanchuk.com) Date: Thu, 17 Feb 2011 20:22:37 -0500 Subject: Unit testing multiprocessing code on Windows In-Reply-To: <4D5DAFEF.8080205@whoosh.ca> References: <4D5DAFEF.8080205@whoosh.ca> Message-ID: <20110217202237.14241i8gnbtt2i9w@semanchuk.com> Quoting Matt Chaput : > Does anyone know the "right" way to write a unit test for code that > uses multiprocessing on Windows? > > The problem is that with both "python setup.py tests" and > "nosetests", when they get to testing any code that starts Processes > they spawn multiple copies of the testing suite (i.e. the new > processes start running tests as if they were started with "python > setup.py tests"/"nosetests"). The test runner in PyDev works properly. > > Maybe multiprocessing is starting new Windows processes by copying > the command line of the current process? But if the command line is > "nosetests", it's a one way ticket to an infinite explosion of > processes. Hi Matt, I assume you're aware of this documentation, especially the item entitled "Safe importing of main module"? http://docs.python.org/release/2.6.6/library/multiprocessing.html#windows HTH P From pwinston at gmail.com Thu Feb 17 20:46:12 2011 From: pwinston at gmail.com (Philip Winston) Date: Thu, 17 Feb 2011 17:46:12 -0800 (PST) Subject: interrupted system call w/ Queue.get Message-ID: We have a multiprocess Python program that uses Queue to communicate between processes. Recently we've seen some errors while blocked waiting on Queue.get: IOError: [Errno 4] Interrupted system call What causes the exception? Is it necessary to catch this exception and manually retry the Queue operation? Thanks. We have some Python 2.5 and 2.6 machines that have run this program for many 1,000 hours with no errors. But we have one 2.5 machine and one 2.7 machine that seem to get the error very often. From prologic at shortcircuit.net.au Thu Feb 17 20:58:27 2011 From: prologic at shortcircuit.net.au (James Mills) Date: Fri, 18 Feb 2011 11:58:27 +1000 Subject: interrupted system call w/ Queue.get In-Reply-To: References: Message-ID: On Fri, Feb 18, 2011 at 11:46 AM, Philip Winston wrote: > We have a multiprocess Python program that uses Queue to communicate > between processes. ?Recently we've seen some errors while blocked > waiting on Queue.get: > > IOError: [Errno 4] Interrupted system call > > What causes the exception? ?Is it necessary to catch this exception > and manually retry the Queue operation? ?Thanks. Are you getting this when your application is shutdown ? I'm pretty sure you can safely ignore this exception and continue. cheers James -- -- James Mills -- -- "Problems are solved by method" From wuwei23 at gmail.com Thu Feb 17 20:59:38 2011 From: wuwei23 at gmail.com (alex23) Date: Thu, 17 Feb 2011 17:59:38 -0800 (PST) Subject: return an object of a different class References: Message-ID: <960d5210-03a8-44ae-88cc-7c3cd6020e67@h40g2000pre.googlegroups.com> Jean-Michel Pichavant wrote: > You simply don't return inconsistent types with a return statement. This > is a general rule in programming that has probably exceptions but > regarding what you're saying, you clearly don't want to do that. I don't think they were intended to be inconsistent types, but subclasses of the same type. Returning different subclasses is exactly what a factory is for. And given Python's propensity for duck typing, they don't even really need to be subclassed for the same object, they just need the interface that is required. > Immagine the following code: > > oNumber = MyNumbers(random.int(100)) # note that oNumber is not a > MyNumbers instance... quite confusing don't you think ? > oNumber. ... wait a minute, which methods am I allowed to call ??? > SmallNumbers adn BigNumbers have differents methods. What if they have different implementations rather than methods? From rantingrick at gmail.com Thu Feb 17 21:11:19 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 17 Feb 2011 18:11:19 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: On Feb 16, 4:07?pm, Xah Lee wrote: > Vast majority of computer languages use ASCII as its character set. > This means, it jams multitude of operators into about 20 symbols. > Often, a symbol has multiple meanings depending on contex. I think in theory the idea of using Unicode chars is good, however in reality the implementation would be a nightmare! A wise man once said: "The road to hell is paved in good intentions". ;-) If we consider all the boundaries that exist between current (programming) languages (syntax, IDE's, paradigms, etc) then we will realize that adding *more* symbols does not help, no, it actually hinders! And Since Unicode is just a hodgepodge encoding of many regional (natural) languages --of which we have too many already in this world!-- proliferating Unicode symbols in source code only serves to further complicate our lives with even *more* multiplicity! Those of us on the *inside* know that Unicode is nothing more than an poor attempt to monkey patch multiplicity. And that statement barely scratches the surface of an underlying disease that plagues all of human civilization. The root case is selfishness, which *then* propagates up and manifests itself as multiplicity in our everyday lives. It starts as the simple selfish notion of "me" against "other" and then extrapolates exponentially into the collective of "we" against "others". This type of grouping --or selfish typecasting if you will-- is impeding the furtherer evolution of homo sapiens. Actually we are moving at a snails pace when we could be moving at the speed of light! We *should* be evolving as a genetic algorithm but instead we are the ignorant slaves of our own collective selfishness reduced to naive and completely random implementations of bozosort! Now don't misunderstand all of this as meaning "multiplicity is bad", because i am not suggesting any such thing! On the contrary, multiplicity is VERY important in emerging problem domains. Before such a domain is understood by the collective unconscience we need options (multiplicity!) from which to choose from. However, once a "collective understanding" is reached we must reign in the multiplicity or it will become yet another millstone around our evolutionary necks, slowing our evolution. But multiplicity is just the very beginning of a downward spiral of devolution. Once you allow multiplicity to become the sport of Entropy, it may be too late for recovery! Entropy leads to shock (logical disorder) which then leads to stagnation (no logical order at all!). At this point we loose all forward momentum in our evolution. And why? Because of nothing more than self gratifying SELFISHNESS. Anyone with half a brain understands the metric system is far superior (on many levels) then any of the other units of measurement. However again we have failed to reign in the multiplicity and so entropy has run a muck, and we are like a deer "caught-in-the-headlights" of the shock of our self induced devolution and simultaneously entirely incapable of seeing the speeding mass that is about to plow over us with a tremendous kinetic energy -- evolutionary stagnation! Sadly this disease of selfishness infects many aspects of the human species to the very detriment of our collective evolution. Maybe one day we will see the light of logic and choose to unite in a collective evolution. Even after thousands of years we are but infants on the evolutionary scale because we continue to feed the primal urges of selfishness. From steve+comp.lang.python at pearwood.info Thu Feb 17 21:25:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Feb 2011 02:25:39 GMT Subject: return an object of a different class References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> <1297953588.4951.1.camel@localhost.localdomain> <4D5D4510.3030402@mrabarnett.plus.com> Message-ID: <4d5dd8a3$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Feb 2011 15:53:14 -0800, Westley Mart?nez wrote: >> > Python 3 removed longs because they were ... cryptonic! >> > >> Strictly speaking, they weren't removed. ints were removed and long was >> renamed int. > My point stands. Your point is wrong. Ints and longs weren't unified because it is "cryptonic" (cryptic?), but to avoid the user needing to care about the difference between ints and longs. I've been coding in Python since version 1.5, and I can tell you I hated the need to write code like this: def make_int(obj): try: return int(obj) except ValueError: return long(int) To say nothing of: def add(x, y): try: return x+y except OverflowError: return long(x)+long(y) Having the int class automatically promote instances to long as needed was a HUGE win for simplicity and readability, while still saving memory and performance for small ints. Still not convinced that it's allowed to return objects of a different type? From Python 3.1: >>> reversed >>> reversed((1,2,3)) >>> reversed("abcd") >>> reversed([1,2,3]) >>> reversed(range(10)) -- Steven From cthun_117 at qmail.net.au Thu Feb 17 21:40:00 2011 From: cthun_117 at qmail.net.au (Cthun) Date: Thu, 17 Feb 2011 21:40:00 -0500 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: On 17/02/2011 9:11 PM, rantingrick wrote: . On Feb 16, 4:07 pm, Xah Lee wrote: .> Vast majority of computer languages use ASCII as its character set. .> This means, it jams multitude of operators into about 20 symbols. .> Often, a symbol has multiple meanings depending on contex. . . I think in theory the idea of using Unicode chars is good, however in . reality the implementation would be a nightmare! A wise man once . said: "The road to hell is paved in good intentions". ;-) . . If we consider all the boundaries that exist between current . (programming) languages (syntax, IDE's, paradigms, etc) then we will . realize that adding *more* symbols does not help, no, it actually . hinders! And Since Unicode is just a hodgepodge encoding of many . regional (natural) languages --of which we have too many already in . this world! What does your aversion to cultural diversity have to do with Lisp, rantingrick? Gee, I do hope you're not a racist, rantingrick. . -- proliferating Unicode symbols in source code only serves . to further complicate our lives with even *more* multiplicity! . . Those of us on the *inside* know that Unicode is nothing more than an . poor attempt to monkey patch multiplicity. And that statement barely . scratches the surface of an underlying disease that plagues all of . human civilization. The root case is selfishness, which *then* . propagates up and manifests itself as multiplicity in our everyday . lives. It starts as the simple selfish notion of "me" against "other" . and then extrapolates exponentially into the collective of "we" . against "others". . . This type of grouping --or selfish typecasting if you will-- is . impeding the furtherer evolution of homo sapiens. Actually we are . moving at a snails pace when we could be moving at the speed of light! . We *should* be evolving as a genetic algorithm but instead we are the . ignorant slaves of our own collective selfishness reduced to naive and . completely random implementations of bozosort! What does that have to do with Lisp, rantingrick? . Now don't misunderstand all of this as meaning "multiplicity is bad", . because i am not suggesting any such thing! On the contrary, . multiplicity is VERY important in emerging problem domains. Before . such a domain is understood by the collective unconscience we need . options (multiplicity!) from which to choose from. However, once a . "collective understanding" is reached we must reign in the . multiplicity or it will become yet another millstone around our . evolutionary necks, slowing our evolution. Classic illogic. Evolution depends upon diversity as grist for the mill of selection, rantingrick. A genetically homogeneous population cannot undergo allele frequency shifts, rantingrock. . But multiplicity is just the very beginning of a downward spiral of . devolution. Once you allow multiplicity to become the sport of . Entropy, it may be too late for recovery! Entropy leads to shock . (logical disorder) which then leads to stagnation (no logical order at . all!). At this point we loose all forward momentum in our evolution. . And why? Because of nothing more than self gratifying SELFISHNESS. . . Anyone with half a brain understands the metric system is far superior . (on many levels) then any of the other units of measurement. However . again we have failed to reign in the multiplicity and so entropy has . run a muck, and we are like a deer "caught-in-the-headlights" of the . shock of our self induced devolution and simultaneously entirely . incapable of seeing the speeding mass that is about to plow over us . with a tremendous kinetic energy -- evolutionary stagnation! . . Sadly this disease of selfishness infects many aspects of the human . species to the very detriment of our collective evolution. Maybe one . day we will see the light of logic and choose to unite in a collective . evolution. Even after thousands of years we are but infants on the . evolutionary scale because we continue to feed the primal urges of . selfishness. What does any of that have to do with Lisp, rantingrick? And you omitted the #1 most serious objection to Xah's proposal, rantingrick, which is that to implement it would require unrealistic things such as replacing every 101-key keyboard with 10001-key keyboards and training everyone to use them. Xah would have us all replace our workstations with machines that resemble pipe organs, rantingrick, or perhaps the cockpits of the three surviving Space Shuttles. No doubt they'd be enormously expensive, as well as much more difficult to learn to use, rantingrick. From drsalists at gmail.com Thu Feb 17 21:49:23 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 17 Feb 2011 18:49:23 -0800 Subject: interrupted system call w/ Queue.get In-Reply-To: References: Message-ID: On Thu, Feb 17, 2011 at 5:46 PM, Philip Winston wrote: > We have a multiprocess Python program that uses Queue to communicate > between processes. Recently we've seen some errors while blocked > waiting on Queue.get: > > IOError: [Errno 4] Interrupted system call > > What causes the exception? Is it necessary to catch this exception > and manually retry the Queue operation? Thanks. > > We have some Python 2.5 and 2.6 machines that have run this program > for many 1,000 hours with no errors. But we have one 2.5 machine and > one 2.7 machine that seem to get the error very often. > You're getting this: #define EINTR 4 /* Interrupted system call */ It most likely means that a signal is interrupting a system call (an interaction with the kernel, not just os.system). Google for EINTR for more info. Whatever callable is getting this error, at root, probably should be dealing with retrying the system call that got interrupted. However, it can sometimes be dealt with higher in the call stack, as a sort of bandaid. This is sadly frequently ignored in application programming. It's some kernel dev's favorite complaint about us. One good way of dealing with this is to use the following function, wrapped around any system calls: def retry_on_eintr(function, *args, **kw): while True: try: return function(*args, **kw) except OSError, e: if e.errno == errno.EINTR: continue else: raise If you find standard library code that's failing to deal with EINTR, it's legitimate to submit a bug report about it. Another way around the issue is to avoid signals. But that's not always practical. How can you tell what's using system calls? It can be hard, but you can usually use strace or truss or ktrace or par or trace to find out. You can also add a little code to log all your tracebacks somewhere, inspect the log periodically, and add a retry_on_eintr as needed in the places identified. Also, most *ix's will have a .h somewhere listing them - on one of my Ubuntu systems, it's at /usr/include/bits/syscall.h. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cor at clsnet.nl Thu Feb 17 21:55:47 2011 From: cor at clsnet.nl (Cor Gest) Date: Fri, 18 Feb 2011 02:55:47 +0000 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: <87lj1egifg.fsf@andromeda.clsnet.nl> Some entity, AKA Cthun , wrote this mindboggling stuff: (selectively-snipped-or-not-p) > And you omitted the #1 most serious objection to Xah's proposal, > rantingrick, which is that to implement it would require unrealistic > things such as replacing every 101-key keyboard with 10001-key > keyboards and training everyone to use them. Xah would have us all > replace our workstations with machines that resemble pipe organs, > rantingrick, or perhaps the cockpits of the three surviving Space > Shuttles. No doubt they'd be enormously expensive, as well as much > more difficult to learn to use, rantingrick. Atleast it should try to mimick a space-cadet keyboard, shouldn't it? Cor -- Monosyllabisch antwoorden is makkelijker ik kan mij zelfs melk veroorloven Geavanceerde politieke correctheid is niet te onderscheiden van sarcasme First rule of enaging in a gunfight: HAVE A GUN SPAM DELENDA EST http://www.spammesenseless.nl From drsalists at gmail.com Thu Feb 17 21:59:44 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 17 Feb 2011 18:59:44 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: I prefer special symbol "congestion" to special symbol proliferation. A lot. A language with few special symbols looks less like line noise, is easier to read and write, and is easier to google for answers about. I guess nothing's perfect. On Wed, Feb 16, 2011 at 2:07 PM, Xah Lee wrote: > might be interesting. > > ?Problems of Symbol Congestion in Computer Languages (ASCII Jam; > Unicode; Fortress)? > http://xahlee.org/comp/comp_lang_unicode.html > > -------------------------------------------------- > Problems of Symbol Congestion in Computer Languages (ASCII Jam; > Unicode; Fortress) > > Xah Lee, 2011-02-05, 2011-02-15 > > Vast majority of computer languages use ASCII as its character set. > This means, it jams multitude of operators into about 20 symbols. > Often, a symbol has multiple meanings depending on contex. Also, a > sequence of chars are used as a single symbol as a workaround for lack > of symbols. Even for languages that use Unicode as its char set (e.g. > Java, XML), often still use the ~20 ASCII symbols for all its > operators. The only exceptions i know of are Mathematica, Fortress, > APL. This page gives some examples of problems created by symbol > congestion. > > ------------------------------- > Symbol Congestion Workarounds > > -------------------- > Multiple Meanings of a Symbol > > Here are some common examples of a symbol that has multiple meanings > depending on context: > > In Java, [ ] is a delimiter for array, also a delimiter for getting a > element of array, also as part of the syntax for declaring a array > type. > > In Java and many other langs, ( ) is used for expression grouping, > also as delimiter for arguments of a function call, also as delimiters > for parameters of a function's declaration. > > In Perl and many other langs, : is used as a separator in a ternary > expression e.g. (test ? "yes" : "no"), also as a namespace separator > (e.g. use Data::Dumper;). > > In URL, / is used as path separators, but also as indicator of > protocol. e.g. http://example.org/comp/unicode.html > > In Python and many others, < is used for ?less than? boolean operator, > but also as a alignment flag in its ?format? method, also as a > delimiter of named group in regex, and also as part of char in other > operators that are made of 2 chars, e.g.: << <= <<= <>. > > -------------------- > Examples of Multip-Char Operators > > Here are some common examples of operators that are made of multiple > characters: || && == <= != ** =+ =* := ++ -- :: // /* (* ? > > ------------------------------- > Fortress ? Unicode > > The language designer Guy Steele recently gave a very interesting > talk. See: Guy Steele on Parallel Programing. In it, he showed code > snippets of his language Fortress, which freely uses Unicode as > operators. > > For example, list delimiters are not the typical curly bracket {1,2,3} > or square bracket [1,2,3], but the unicode angle bracket ?1,2,3?. > (See: Matching Brackets in Unicode.) It also uses the circle plus ? as > operator. (See: Math Symbols in Unicode.) > > ------------------------------- > Problems of Symbol Congestion > > I really appreciate such use of unicode. The tradition of sticking to > the 95 chars in ASCII of 1960s is extremely limiting. It creates > complex problems manifested in: > > * String Escape mechanism (C's backslash \n, \/, ?, widely > adopted.) > * Complex delimiters for strings. (Python's triple quotes and > perl's variable delimiters q() q[] q{} m//, and heredoc. (See: Strings > in Perl and Python ? Heredoc mechanism in PHP and Perl.) > * Crazy leaning toothpicks syndrome, especially bad in emacs > regex. > * Complexities in character representation (See: Emacs's Key > Notations Explained (/r, ^M, C-m, RET, , M-, meta) ? HTML > entities problems. See: HTML Entities, Ampersand, Unicode, Semantics.) > * URL Percent Encoding problems and complexities: Javascript > Encode URL, Escape String > > All these problems occur because we are jamming so many meanings into > about 20 symbols in ASCII. > > See also: > > * Computer Language Design: Strings Syntax > * HTML6: Your JSON and SXML Simplified > > Most of today's languages do not support unicode in function or > variable names, so you can forget about using unicode in variable > names (e.g. ?=3) or function names (e.g. ?lambda? as ??? or ?function? > as ???), or defining your own operators (e.g. ???). > > However, there are a few languages i know that do support unicode in > function or variable names. Some of these allow you to define your own > operators. However, they may not allow unicode for the operator > symbol. See: Unicode Support in Ruby, Perl, Python, javascript, Java, > Emacs Lisp, Mathematica. > > Xah > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjns1989 at gmail.com Thu Feb 17 22:28:23 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Thu, 17 Feb 2011 22:28:23 -0500 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <87lj1egifg.fsf@andromeda.clsnet.nl> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> Message-ID: <20110218032823.GA29770@pavo.local> On Thu, Feb 17, 2011 at 09:55:47PM EST, Cor Gest wrote: > Some entity, AKA Cthun , [..] > > And you omitted the #1 most serious objection to Xah's proposal, > > rantingrick, which is that to implement it would require unrealistic > > things such as replacing every 101-key keyboard with 10001-key > > keyboards and training everyone to use them. Xah would have us all > > replace our workstations with machines that resemble pipe organs, > > rantingrick, or perhaps the cockpits of the three surviving Space > > Shuttles. No doubt they'd be enormously expensive, as well as much > > more difficult to learn to use, rantingrick. > At least it should try to mimick a space-cadet keyboard, shouldn't it? Implementation details, and not very accurate at that.. the APL keyboard has not additional keys and yet it has the potential to add up to 100 additional symbols to the US-ASCII keyboard, half of which are produced via a single modifier.. same as upper-case letters. So unless more than 50+20 = 70 symbols are needed the keyboard conversion would cost about.. what.. $2.00 in stickers and maybe ten minutes to place them. Maybe the problem lies elsewhere..? cj From rantingrick at gmail.com Thu Feb 17 22:29:10 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 17 Feb 2011 19:29:10 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: On Feb 17, 8:40?pm, Cthun wrote: > What does your aversion to cultural diversity have to do with Lisp, > rantingrick? Gee, I do hope you're not a racist, rantingrick. Why must language be constantly "connected-at-the-hip" to cultural diversity? People have this irrational fear that if we create a single universal language then *somehow* freedom have been violated. You *do* understand that language is just a means of communication, correct? And i would say a very inefficient means. However, until telekinesis becomes common-place the only way us humans have to communicate is through a fancy set of grunts and groans. Since that is the current state of our communication thus far, would it not be beneficial that at least we share a common world wide mapping of this noise making? Hey, wait, i have an idea... maybe some of us should drive on the right side of the road and some on the left. This way we can be unique (psst: SELFISH) from one geographic location on the earth to another geographic location on the earth. Surely this multiplicity would not cause any problems? Because, heck, selfishness is so much more important than anyones personal safety anyway Do you see how this morphs into a foolish consistency? > . Now don't misunderstand all of this as meaning "multiplicity is bad", > . because i am not suggesting any such thing! On the contrary, > . multiplicity is VERY important in emerging problem domains. Before > . such a domain is understood by the collective unconscience we need > . options (multiplicity!) from which to choose from. However, once a > . "collective understanding" is reached we must reign in the > . multiplicity or it will become yet another millstone around our > . evolutionary necks, slowing our evolution. > > Classic illogic. Evolution depends upon diversity as grist for the mill > of selection, rantingrick. A genetically homogeneous population cannot > undergo allele frequency shifts, rantingrock. Oh, maybe you missed this paragraph: . Now don't misunderstand all of this as meaning "multiplicity is bad", . because i am not suggesting any such thing! On the contrary, . multiplicity is VERY important in emerging problem domains. Before . such a domain is understood by the collective unconscience we need . options (multiplicity!) from which to choose from. However, once a . "collective understanding" is reached we must reign in the . multiplicity or it will become yet another millstone around our . evolutionary necks, slowing our evolution. Or maybe this one: . I think in theory the idea of using Unicode chars is good, however in . reality the implementation would be a nightmare! A wise man once . said: "The road to hell is paved in good intentions". ;-) Or this one: . If we consider all the boundaries that exist between current . (programming) languages (syntax, IDE's, paradigms, etc) then we will . realize that adding *more* symbols does not help, no, it actually . hinders! And Since Unicode is just a hodgepodge encoding of many . regional (natural) languages --of which we have too many already in . this world! > What does any of that have to do with Lisp, rantingrick? The topic is *ahem*... "Problems of Symbol Congestion in Computer Languages"... of which i think is not only a lisp issue but an issue of any language. (see my comments about selfishness for insight) > And you omitted the #1 most serious objection to Xah's proposal, > rantingrick, which is that to implement it would require unrealistic > things such as replacing every 101-key keyboard with 10001-key keyboards > and training everyone to use them. Xah would have us all replace our > workstations with machines that resemble pipe organs, rantingrick, or > perhaps the cockpits of the three surviving Space Shuttles. No doubt > they'd be enormously expensive, as well as much more difficult to learn > to use, rantingrick. Yes, if you'll read my entire post then you'll clearly see that i disagree with Mr Lee on using Unicode chars in source code. My intention was to educate him on the pitfalls of multiplicity. From anikom15 at gmail.com Thu Feb 17 22:31:08 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 17 Feb 2011 19:31:08 -0800 Subject: return an object of a different class In-Reply-To: <4d5dd8a3$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> <4D5B932E.9000206@free.fr> <4d5d09f3$0$29972$c3e8da3$5496439d@news.astraweb.com> <1297953588.4951.1.camel@localhost.localdomain> <4D5D4510.3030402@mrabarnett.plus.com> <4d5dd8a3$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1297999868.9783.3.camel@localhost.localdomain> On Fri, 2011-02-18 at 02:25 +0000, Steven D'Aprano wrote: > On Thu, 17 Feb 2011 15:53:14 -0800, Westley Mart?nez wrote: > > >> > Python 3 removed longs because they were ... cryptonic! > >> > > >> Strictly speaking, they weren't removed. ints were removed and long was > >> renamed int. > > My point stands. > > Your point is wrong. Ints and longs weren't unified because it is > "cryptonic" (cryptic?), but to avoid the user needing to care about the > difference between ints and longs. I've been coding in Python since > version 1.5, and I can tell you I hated the need to write code like this: > > > def make_int(obj): > try: > return int(obj) > except ValueError: > return long(int) > > To say nothing of: > > def add(x, y): > try: > return x+y > except OverflowError: > return long(x)+long(y) > > > Having the int class automatically promote instances to long as needed > was a HUGE win for simplicity and readability, while still saving memory > and performance for small ints. > > Still not convinced that it's allowed to return objects of a different > type? From Python 3.1: > > >>> reversed > > >>> reversed((1,2,3)) > > >>> reversed("abcd") > > >>> reversed([1,2,3]) > > >>> reversed(range(10)) > > > > -- > Steven But again, these types all have an identical interface. From maillist.tom at gmail.com Thu Feb 17 22:40:06 2011 From: maillist.tom at gmail.com (tom z) Date: Fri, 18 Feb 2011 11:40:06 +0800 Subject: Help: python unicode Message-ID: Hi all~ My script can't work.I've changed my defaultencoding from 'ascii' to 'utf-8',but Python also raises a 'UnicodeEncodeError' error. the error likes this: >>> s=u'La Pe\xf1a' >>>print s UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 5: ... And in my script, there're many 'print' statements.So SOS~~~~ what should i do??? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler at tysdomain.com Thu Feb 17 22:42:12 2011 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Thu, 17 Feb 2011 20:42:12 -0700 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: <4D5DEA94.2060207@tysdomain.com> >My intention was to educate him on the pitfalls of multiplicity. O. that's what you call that long-winded nonsense? Education? You must live in America. Can I hazard a guess that your universal language might be english? Has it not ever occured to you that people take pride in their language? It is part of their culture. And yet you rant on about selfishness? On 2/17/2011 8:29 PM, rantingrick wrote: > On Feb 17, 8:40 pm, Cthun wrote: > >> What does your aversion to cultural diversity have to do with Lisp, >> rantingrick? Gee, I do hope you're not a racist, rantingrick. > Why must language be constantly "connected-at-the-hip" to cultural > diversity? People have this irrational fear that if we create a single > universal language then *somehow* freedom have been violated. > > You *do* understand that language is just a means of communication, > correct? And i would say a very inefficient means. However, until > telekinesis becomes common-place the only way us humans have to > communicate is through a fancy set of grunts and groans. Since that is > the current state of our communication thus far, would it not be > beneficial that at least we share a common world wide mapping of this > noise making? > > Hey, wait, i have an idea... maybe some of us should drive > on the right side of the road and some on the left. This way we can be > unique (psst: SELFISH) from one geographic location on the earth to > another geographic location on the earth. Surely this multiplicity > would not cause any problems? Because, heck, selfishness is so much > more important than anyones personal safety anyway > > Do you see how this morphs into a foolish consistency? > >> . Now don't misunderstand all of this as meaning "multiplicity is bad", >> . because i am not suggesting any such thing! On the contrary, >> . multiplicity is VERY important in emerging problem domains. Before >> . such a domain is understood by the collective unconscience we need >> . options (multiplicity!) from which to choose from. However, once a >> . "collective understanding" is reached we must reign in the >> . multiplicity or it will become yet another millstone around our >> . evolutionary necks, slowing our evolution. >> >> Classic illogic. Evolution depends upon diversity as grist for the mill >> of selection, rantingrick. A genetically homogeneous population cannot >> undergo allele frequency shifts, rantingrock. > Oh, maybe you missed this paragraph: > > . Now don't misunderstand all of this as meaning "multiplicity is > bad", > . because i am not suggesting any such thing! On the contrary, > . multiplicity is VERY important in emerging problem domains. Before > . such a domain is understood by the collective unconscience we need > . options (multiplicity!) from which to choose from. However, once a > . "collective understanding" is reached we must reign in the > . multiplicity or it will become yet another millstone around our > . evolutionary necks, slowing our evolution. > > Or maybe this one: > > . I think in theory the idea of using Unicode chars is good, however > in > . reality the implementation would be a nightmare! A wise man once > . said: "The road to hell is paved in good intentions". ;-) > > Or this one: > > . If we consider all the boundaries that exist between current > . (programming) languages (syntax, IDE's, paradigms, etc) then we > will > . realize that adding *more* symbols does not help, no, it actually > . hinders! And Since Unicode is just a hodgepodge encoding of many > . regional (natural) languages --of which we have too many already in > . this world! > >> What does any of that have to do with Lisp, rantingrick? > The topic is *ahem*... "Problems of Symbol Congestion in Computer > Languages"... of which i think is not only a lisp issue but an issue > of any language. (see my comments about selfishness for insight) > >> And you omitted the #1 most serious objection to Xah's proposal, >> rantingrick, which is that to implement it would require unrealistic >> things such as replacing every 101-key keyboard with 10001-key keyboards >> and training everyone to use them. Xah would have us all replace our >> workstations with machines that resemble pipe organs, rantingrick, or >> perhaps the cockpits of the three surviving Space Shuttles. No doubt >> they'd be enormously expensive, as well as much more difficult to learn >> to use, rantingrick. > Yes, if you'll read my entire post then you'll clearly see that i > disagree with Mr Lee on using Unicode chars in source code. My > intention was to educate him on the pitfalls of multiplicity. > > -- Thanks, Ty From mdaglow at daglowconsulting.com Thu Feb 17 22:44:08 2011 From: mdaglow at daglowconsulting.com (Marta Daglow) Date: Thu, 17 Feb 2011 22:44:08 -0500 Subject: Lamp Engineers for 2 top game companies In-Reply-To: References: Message-ID: Hey I'm working inhouse for two top games companies who are looking for top lamp engineers. If you are interested in knowing more about the details, please feel free to call or email me. Cheers, Marta Daglow President - Games (Social, Online & Console) Daglow Consulting Group PO Box 948 Ross, CA 94957 mdaglow at daglowconsulting.com (415) 461-5845 Recruit | Retain | Inspire From cthun_117 at qmail.net.au Thu Feb 17 22:49:21 2011 From: cthun_117 at qmail.net.au (Cthun) Date: Thu, 17 Feb 2011 22:49:21 -0500 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: On 17/02/2011 10:29 PM, rantingrick wrote: > On Feb 17, 8:40 pm, Cthun wrote: > >> What does your aversion to cultural diversity have to do with Lisp, >> rantingrick? Gee, I do hope you're not a racist, rantingrick. > > Why must language be constantly "connected-at-the-hip" to cultural > diversity? Language is a part of culture, rantingrick. > People have this irrational fear that if we create a single > universal language then *somehow* freedom have been violated. No, it is that if we stop using the others, or forcibly wipe them out, that something irreplaceable will have been lost, rantingrick. > You *do* understand that language is just a means of communication, > correct? Classic unsubstantiated and erroneous claim. A language is also a cultural artifact, rantingrick. If we lose, say, the French language, we lose one of several almost-interchangeable means of communication, rantingrick. But we also lose something as unique and irreplaceable as the original canvas of the Mona Lisa, rantingrick. > And i would say a very inefficient means. However, until > telekinesis becomes common-place the only way us humans have to > communicate is through a fancy set of grunts and groans. Since that is > the current state of our communication thus far, would it not be > beneficial that at least we share a common world wide mapping of this > noise making? What does your question have to do with Lisp, rantingrick? > Hey, wait, i have an idea... maybe some of us should drive > on the right side of the road and some on the left. This way we can be > unique (psst: SELFISH) from one geographic location on the earth to > another geographic location on the earth. Classic illogic. Comparing, say, the loss of the French language to standardizing on this is like comparing the loss of the Mona Lisa to zeroing one single bit in a computer somewhere, rantingrick. > Surely this multiplicity > would not cause any problems? Because, heck, selfishness is so much > more important than anyones personal safety anyway Non sequitur. > Do you see how this morphs into a foolish consistency? What does your classic erroneous presupposition have to do with Lisp, rantingrick? >> Classic illogic. Evolution depends upon diversity as grist for the mill >> of selection, rantingrick. A genetically homogeneous population cannot >> undergo allele frequency shifts, rantingrock. > > Oh, maybe you missed this paragraph What does your classic erroneous presupposition have to do with Lisp, rantingrick? > . Now don't misunderstand all of this as meaning "multiplicity is > bad", > . because i am not suggesting any such thing! On the contrary, > . multiplicity is VERY important in emerging problem domains. Before > . such a domain is understood by the collective unconscience we need > . options (multiplicity!) from which to choose from. However, once a > . "collective understanding" is reached we must reign in the > . multiplicity or it will become yet another millstone around our > . evolutionary necks, slowing our evolution. Classic erroneous presupposition that evolution is supposed to reach a certain point and then stop and stagnate on a single universal standard, rantingrick. > Or maybe this one: > > . I think in theory the idea of using Unicode chars is good, however > in > . reality the implementation would be a nightmare! A wise man once > . said: "The road to hell is paved in good intentions". ;-) Classic unsubstantiated and erroneous claim. I read that one, rantingrick. > Or this one: > > . If we consider all the boundaries that exist between current > . (programming) languages (syntax, IDE's, paradigms, etc) then we > will > . realize that adding *more* symbols does not help, no, it actually > . hinders! And Since Unicode is just a hodgepodge encoding of many > . regional (natural) languages --of which we have too many already in > . this world! Classic unsubstantiated and erroneous claim. I read that one, too, rantingrick. >> What does any of that have to do with Lisp, rantingrick? > > The topic is *ahem*... "Problems of Symbol Congestion in Computer > Languages"... of which i think is not only a lisp issue but an issue > of any language. Classic illogic. The topic of the *thread* is *computer* languages, yet you attacked non-computer languages in the majority of your rant, rantingrick. Furthermore, the topic of the *newsgroup* is the *Lisp subset* of computer languages. > (see my comments about selfishness for insight) What does that have to do with Lisp, rantingrick? >> And you omitted the #1 most serious objection to Xah's proposal, >> rantingrick, which is that to implement it would require unrealistic >> things such as replacing every 101-key keyboard with 10001-key keyboards >> and training everyone to use them. Xah would have us all replace our >> workstations with machines that resemble pipe organs, rantingrick, or >> perhaps the cockpits of the three surviving Space Shuttles. No doubt >> they'd be enormously expensive, as well as much more difficult to learn >> to use, rantingrick. > > Yes, if you'll read my entire post then you'll clearly see that i > disagree with Mr Lee on using Unicode chars in source code. Classic erroneous presuppositions that I did not read your entire post and that I thought you weren't disagreeing with Mr. Lee, rantingrick. > My intention was to educate him on the pitfalls of multiplicity. Classic illogic, since "multiplicity" (also known as "diversity") does not in and of itself have pitfalls, rantingrick. On the other hand, monoculture has numerous well-known pitfalls, rantingrick. From wuwei23 at gmail.com Thu Feb 17 23:04:15 2011 From: wuwei23 at gmail.com (alex23) Date: Thu, 17 Feb 2011 20:04:15 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> rantingrick wrote: > Cthun wrote: > > > What does your aversion to cultural diversity have to do with Lisp, > > rantingrick? Gee, I do hope you're not a racist, rantingrick. > > Why must language be constantly "connected-at-the-hip" to cultural > diversity? People have this irrational fear that if we create a single > universal language then *somehow* freedom have been violated. Because monocultures _die_ and no amount of fascist-like rick-ranting about a One True Way will ever change that. From orgnut at yahoo.com Thu Feb 17 23:15:57 2011 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 17 Feb 2011 20:15:57 -0800 Subject: Newbie getting desperate with for In-Reply-To: References: Message-ID: <48qdnZ28pcPgb8DQnZ2dnUVZ5q6dnZ2d@giganews.com> On 02/17/2011 12:27 AM, Werner wrote: > I have a trivially simple piece of code called timewaster.py: > ____________________________________________________ > > while True: > i = 0 > for i in range(10): > break > _____________________________________________________ > > It runs fine with Eric but when I try to run it from shell... >> ./timewaster.py > ./timewaster.py: line 4: syntax error near unexpected token `(' > ./timewaster.py: line 4: ` for i in range(10):' > > I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python > version 2.6.5, both show the above. > > Before I tear out my hair any more (only 3 left) I thought I'd ask here > what I am doing wrong. > > Best Regards > Werner Dahn A true time waster indeed -- it's an infinite loop that will _never_ end. Others have already about the need of the shebang line to run as a python script, but I'm surprised no one mentioned how truly useless this code is. The i = 0 line is totally unnecessary. The variable i is created and set to zero by the first iteration of the for loop. The break will abort the for loop (NOT the while loop) in the first iteration, and the 2nd through the 10th iterations will be skipped altogether. This effectively leaves your code as: while True: pass # Do nothing, forever An empty loop as a time delay can occasionally be useful, but as a practical matter, a for loop with only 10 (empty/pass) iterations is probably too short for anything useful. Instead of being empty, do some more complex (but ignored) operation -- say math.sqrt() or math.sin() for example -- and a much larger repetition count. But it's likely that does use up processor cycles unnecessarily, although it can give you delays of fractions of seconds. If you want delays greater than a second, check out the time.sleep() function. -=- Larry -=- From hidura at gmail.com Thu Feb 17 23:19:55 2011 From: hidura at gmail.com (Hidura) Date: Fri, 18 Feb 2011 00:19:55 -0400 Subject: How to conserve the integrity of the string from a database response using Python Message-ID: Hello, i am using py-postgresql as the driver the database, when make a select to a string with non-ASCII characters, the response replace the character with "?" what can i make to change this to the correct character? This is my code: class decodify: def __init__(self): db = pgDriver.connect(user = 'demo', password='demo' database='hidura_karinapp', host='localhost', port='5432') d = db.prepare("""SELECT modules_reg.code FROM modules_reg, domain_reg, sbdomain_reg, sbdomdl_asc where(modules_reg.id = sbdomdl_asc.module AND modules_reg.mdname = 'police' AND sbdomain_reg.id = sbdomdl_asc.domain AND sbdomain_reg.domain = domain_reg.id AND domain_reg.dname = 'bmsuite.com' AND sbdomain_reg.sbname = 'www')""") s = d() print(s) if __name__ == '__main__': decodify() -- Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.gavana at gmail.com Thu Feb 17 23:40:19 2011 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Fri, 18 Feb 2011 09:40:19 +0500 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: <1297952429.21461.1421183197@webmail.messagingengine.com> References: <1297925076.8054.1421127991@webmail.messagingengine.com> <1297952429.21461.1421183197@webmail.messagingengine.com> Message-ID: Hi Malcolm, On 17 February 2011 19:20, wrote: > Hi Andrea, > > Have you tried temporarily turning off your Windows firewall software > and/or any locally installed internet security software like Norton, > Avast, etc? You don't need to turn off your entire security package, > just the component that controls internet access. I'd love to, but it's not under my control. The IT department has an iron grip on these things and there is no way I can do what you proposed :-( > > If the problem can not be resolved locally, then I believe you need to > contact your IT department to have them create the firewall rules that > will allow you to access gmail services. I'm basing that suggestion on > googling the various error messages (10060, 10061) you received and > reading the answers. That's my interpretation, anyway. I though that I could do what Chrome/Firefox do: as far as I can understand, they seem to use the company proxy settings to access the web (and this is also what the "about:config" in Firefox is telling me: it gives all the proxy servers and ports I need). However, even the simplest piece of code using urllib2 and trying to read the Python web page like this: import urllib2 user_agent = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100915\ Ubuntu/10.04 (lucid) Firefox/3.6.10' request = urllib2.Request('http://www.python.org/') request.add_header('User-agent', user_agent ) proxy_info = { 'user' : username, 'pass' : password, 'host' : proxy_server, 'port' : 993 # or 8080 or whatever } proxy = "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info proxy_support = urllib2.ProxyHandler({"http" : proxy}) opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) urllib2.install_opener(opener) urllib2.urlopen(request) Fails with a variety of errors depending on which port I use: - Port 80: urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ) - Port 143: urllib2.URLError: - Port 8080: urllib2.HTTPError: HTTP Error 403: Forbidden ( The server denied the specified Uniform Resource Locator (URL). Contact the server administrator. ) Etc... etc... I am going to try all the ports from 1 to 10000 and see what happens, just for the fun of it. I am sure I will get 10000 errors, with mixed frequency. :-( :-( If someone can see what I am doing wrong, please do let me know... I'm running our of ideas... > > I'm a big fan of your wxPython and GUI builder contributions!! Thank you, I'm happy you found them useful! Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ ==> Never *EVER* use RemovalGroup for your house removal. You'll regret it forever. http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <== From rantingrick at gmail.com Thu Feb 17 23:47:57 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 17 Feb 2011 20:47:57 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> Message-ID: On Feb 17, 10:04?pm, alex23 wrote: > rantingrick wrote: > > Cthun wrote: > > > > What does your aversion to cultural diversity have to do with Lisp, > > > rantingrick? Gee, I do hope you're not a racist, rantingrick. > > > Why must language be constantly "connected-at-the-hip" to cultural > > diversity? People have this irrational fear that if we create a single > > universal language then *somehow* freedom have been violated. > > Because monocultures _die_ You lack vision. What is evolution? Evolution is the pursuit of perfection at the expense of anything and everything! But what evolution lacks is self awareness. Evolution is really a bumbling idiot. Intelligent agents should not emulate classical evolution, no, we should mold it and shape it ourselves! Darwinian evolution is an archaic and slow process which takes eons to bring about even the smallest changes. However evolution guided by "intelligent agents" is exponential. Do you think the earth is anything special? Do you think some talking monkeys is anything special? Do you think tens of thousands of years are anything but the blink of an eye? All of what you see and know is but teeny tiny baby steps in the short life of evolution. The system has not even made it from the couch to the coffee table yet without loosing balance and falling on it proverbial buttocks! And you are concerned with something as small as human cultures and language diversity! Open your eyes man! NEWSFLASH: Humans are NOT the prize of the Universe. We are merely a bump along the way. Stop self aggrandizing for a moment so you can see reality. That does not mean we cannot contribute great things! But we are here for a very short time on a galactic scale. Stop being selfish and realize what you are, who you are, and where you should be going. Next time you pass an ant hill look down at one the ants and imagine that the ant is you... then you will *get* it. From rantingrick at gmail.com Fri Feb 18 00:38:21 2011 From: rantingrick at gmail.com (rantingrick) Date: Thu, 17 Feb 2011 21:38:21 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> Message-ID: When the sun expands into a red giant and destroys the remaining life left on this pathetic rock and the entire puny human species have been transcended by the *next* evolution of intelligent agents (hopefully before going extinct!) do you really think any advanced lifeforms are going to look back and give a flying fig about the selfishness of the human species? "Well they did not give much to evolution, but hey, they had TV's, Elvis, microwave pizza, and muti-culturalism, woo-hoo!" *Your* thought process are an evolutionary dead end my friend! All of what you see and know is nothing in the greater scheme of things. What do you think, some future anthropologist is going to dig up human bones like we do with dinosaur bones? Are you insane? Where will you dig when the earth is non-existent? Where will you start your research of human civilization when every piece of matter that proved our existence has been reformed into energy? All we have at the end of this gigantic game is that which we can contribute to the *next step* of evolution. The best we can hope for is to successfully pass the "baton of knowledge" to the next runner. Nothing we create is going to survive time... NOTHING! Not any structure, not any system of government, not any selfish human sub- culture, not any piece of art, not even the entire human culture, nothing! Only one *thing* is immortal, Evolution. And the only way for us to be immortal is by offering a substantial building block to that system. Assimilation is the way of the Universe, like it or not. From nagle at animats.com Fri Feb 18 00:43:37 2011 From: nagle at animats.com (John Nagle) Date: Thu, 17 Feb 2011 21:43:37 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <87lj1egifg.fsf@andromeda.clsnet.nl> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> Message-ID: <4d5e0708$0$10591$742ec2ed@news.sonic.net> On 2/17/2011 6:55 PM, Cor Gest wrote: > Some entity, AKA Cthun, > wrote this mindboggling stuff: > (selectively-snipped-or-not-p) > > >> And you omitted the #1 most serious objection to Xah's proposal, >> rantingrick, which is that to implement it would require unrealistic >> things such as replacing every 101-key keyboard with 10001-key >> keyboards and training everyone to use them. Xah would have us all >> replace our workstations with machines that resemble pipe organs, >> rantingrick, or perhaps the cockpits of the three surviving Space >> Shuttles. No doubt they'd be enormously expensive, as well as much >> more difficult to learn to use, rantingrick. > > At least it should try to mimick a space-cadet keyboard, shouldn't it? I've used both the "MIT Space Cadet" keyboard on a Symbolics LISP machine, and the Stanford SAIL keyboard. There's something to be said for having more mathematical symbols. Some programs use a bigger character set. MathCAD, for example, has a broader range of mathematical symbols on the input side than ASCII offers. They're not decorative; MathCAD has different "=" symbols for assignment, algebraic equivalence, identity, and comparison. I've previously mentioned that Python suffers in a few places from unwanted overloading. Using "+" for concatenation of strings, then extending that to vectors, resulted in undesirable semantics. "+" on arrays from "numpy", and on built-in vectors behave quite differently. A dedicated concatenation operator would have avoided that mess. C++ has worse problems, because it uses < and > as both brackets and operators. This does horrible things to the syntax. However, adding a large number of new operators or new bracket types is probably undesirable. John Nagle From stefan_ml at behnel.de Fri Feb 18 00:51:00 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 18 Feb 2011 06:51:00 +0100 Subject: Converting getCSS Count Code from java to python In-Reply-To: References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> Message-ID: SMERSH009, 17.02.2011 22:46: > am still stuck with the following error when I try to > print self.count_css_matches('css=[id="listGuests"]') > I've also included the Selenium code below. Any further help would be > appreciated. > > Traceback (most recent call last): > File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line > 27, in test_untitled > print self.count_css_matches('css=[id="listGuests"]') > File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line > 17, in count_css_matches > return int(selenium.get_eval(self, java_script_code)) > TypeError: unbound method get_eval() must be called with selenium > instance as first argument (got Untitled instance instead) > > ---------------------------------------------------------------------- > > > from selenium import selenium > import unittest, time > from datetime import datetime > > class Untitled(unittest.TestCase): > def count_css_matches(self, css_locator): > java_script_code = ''' > var cssMatches = eval_css("%s", window.document); > cssMatches.length;''' % css_locator > return int(selenium.get_eval(self, java_script_code)) > #return int(selenium.getEval(java_script_code)) You want to use "self.selenium" here, not "selenium". Stefan > def setUp(self): > self.verificationErrors = [] > self.selenium = selenium("localhost", 4445, "*chrome", "http:// > www.guestlistnation.com/") > self.selenium.start() > > > > def test_untitled(self): > sel = self.selenium > sel.window_maximize() > sel.open("/Events.aspx?Location=SAN FRANCISCO") > > sel.click("css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails']") > sel.wait_for_page_to_load("30000") > > print self.count_css_matches('css=[id="listGuests"]') > > if __name__ == "__main__": > unittest.main() > > From smersh009x at gmail.com Fri Feb 18 01:25:44 2011 From: smersh009x at gmail.com (SMERSH009) Date: Thu, 17 Feb 2011 22:25:44 -0800 (PST) Subject: Converting getCSS Count Code from java to python References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> Message-ID: <1773a6b2-22e1-4ab9-a6d4-47903500069a@a8g2000pri.googlegroups.com> On Feb 17, 9:51?pm, Stefan Behnel wrote: > SMERSH009, 17.02.2011 22:46: > > > > > am still stuck with the following error when I try to > > print self.count_css_matches('css=[id="listGuests"]') > > I've also included the Selenium code below. Any further help would be > > appreciated. > > > Traceback (most recent call last): > > ? ?File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line > > 27, in test_untitled > > ? ? ?print self.count_css_matches('css=[id="listGuests"]') > > ? ?File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line > > 17, in count_css_matches > > ? ? ?return int(selenium.get_eval(self, java_script_code)) > > TypeError: unbound method get_eval() must be called with selenium > > instance as first argument (got Untitled instance instead) > > > ---------------------------------------------------------------------- > > > from selenium import selenium > > import unittest, time > > from datetime import datetime > > > class Untitled(unittest.TestCase): > > ? ? ?def count_css_matches(self, css_locator): > > ? ? ? ? ?java_script_code = ''' > > ? ? ? ? ? ? ?var cssMatches = eval_css("%s", window.document); > > ? ? ? ? ? ? ?cssMatches.length;''' % css_locator > > ? ? ? ? ?return int(selenium.get_eval(self, java_script_code)) > > ? ? ? ? ?#return int(selenium.getEval(java_script_code)) > > You want to use "self.selenium" here, not "selenium". > > Stefan > > > ? ? ?def setUp(self): > > ? ? ? ? ?self.verificationErrors = [] > > ? ? ? ? ?self.selenium = selenium("localhost", 4445, "*chrome", "http:// > >www.guestlistnation.com/") > > ? ? ? ? ?self.selenium.start() > > > ? ? ?def test_untitled(self): > > ? ? ? ? ?sel = self.selenium > > ? ? ? ? ?sel.window_maximize() > > ? ? ? ? ?sel.open("/Events.aspx?Location=SAN FRANCISCO") > > > sel.click("css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails']") > > ? ? ? ? ?sel.wait_for_page_to_load("30000") > > > ? ? ? ? ?print self.count_css_matches('css=[id="listGuests"]') > > > if __name__ == "__main__": > > ? ? ?unittest.main() > > Wow-- you guys rock --big time! :)) Here is the final code with a working examples: from selenium import selenium import unittest, time from datetime import datetime class Untitled(unittest.TestCase): def count_css_matches(self, css_locator): java_script_code = ''' var cssMatches = eval_css("%s", window.document); cssMatches.length;''' % css_locator return self.selenium.get_eval(java_script_code) def setUp(self): self.verificationErrors = [] self.selenium = selenium("localhost", 4445, "*chrome", "http:// www.guestlistnation.com/") self.selenium.start() def test_untitled(self): sel = self.selenium sel.window_maximize() sel.open("/Events.aspx?Location=SAN FRANCISCO") sel.click("css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails']") sel.wait_for_page_to_load("30000") print self.count_css_matches("[id='listGuests'] > option") # prints number of options in dropdown with 'id=listGuests' print self.count_css_matches("*") #prints all on page if __name__ == "__main__": unittest.main() From sathish at solitontech.com Fri Feb 18 01:26:09 2011 From: sathish at solitontech.com (Sathish S) Date: Fri, 18 Feb 2011 11:56:09 +0530 Subject: Python Path registry Key Message-ID: Hi Ppl, I'm trying to launch IDLE from another application. For this I need the python directory path. I have been trying to get the Active Python versions path from the Windows registry. However, these registry entries seem not be consistent across various stations, that i checked. I'm reading the following resitry key to get the active versions path: Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Python.exe. There are two entries in this key. Some stations have only one entry. Some do not have both. Probably they were removed while python was uninstall ed and was not added again when it was installed again. So what will be a good solution to get the Python path ? Thanks, Sathish -------------- next part -------------- An HTML attachment was scrubbed... URL: From anikom15 at gmail.com Fri Feb 18 01:27:45 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 17 Feb 2011 22:27:45 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> Message-ID: <1298010465.11369.4.camel@localhost.localdomain> On Thu, 2011-02-17 at 21:38 -0800, rantingrick wrote: > That was a very insightful point-of-view. Perhaps you should write a book or blog, as I'd be very interested in reading more about what you have to say. From anikom15 at gmail.com Fri Feb 18 01:30:04 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Thu, 17 Feb 2011 22:30:04 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <20110218032823.GA29770@pavo.local> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <20110218032823.GA29770@pavo.local> Message-ID: <1298010604.11369.6.camel@localhost.localdomain> On Thu, 2011-02-17 at 22:28 -0500, Chris Jones wrote: > On Thu, Feb 17, 2011 at 09:55:47PM EST, Cor Gest wrote: > > Some entity, AKA Cthun , > > [..] > > > > And you omitted the #1 most serious objection to Xah's proposal, > > > rantingrick, which is that to implement it would require unrealistic > > > things such as replacing every 101-key keyboard with 10001-key > > > keyboards and training everyone to use them. Xah would have us all > > > replace our workstations with machines that resemble pipe organs, > > > rantingrick, or perhaps the cockpits of the three surviving Space > > > Shuttles. No doubt they'd be enormously expensive, as well as much > > > more difficult to learn to use, rantingrick. > > > At least it should try to mimick a space-cadet keyboard, shouldn't it? > > Implementation details, and not very accurate at that.. the APL keyboard > has not additional keys and yet it has the potential to add up to 100 > additional symbols to the US-ASCII keyboard, half of which are produced > via a single modifier.. same as upper-case letters. So unless more than > 50+20 = 70 symbols are needed the keyboard conversion would cost about.. > what.. $2.00 in stickers and maybe ten minutes to place them. > > Maybe the problem lies elsewhere..? > > cj > $2.00 * thousands of programmers -> thousands of dollars + thousands of lost training time; not to mention code conversion. From kianseong.low at logisticsconsulting.asia Fri Feb 18 01:32:49 2011 From: kianseong.low at logisticsconsulting.asia (low kian seong) Date: Fri, 18 Feb 2011 14:32:49 +0800 Subject: Help: python unicode In-Reply-To: References: Message-ID: On Fri, Feb 18, 2011 at 11:40 AM, tom z wrote: > Hi all~ > My script can't work.I've changed my defaultencoding from 'ascii' to > 'utf-8',but Python also raises a 'UnicodeEncodeError' error. > > the error likes this: > > >>> s=u'La Pe\xf1a' > >>>print s > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in > position 5: ... > >>> s=u'La Pe\xf1a' >>> print s.encode('utf-8') La Pe?a ? or use smart_str from django ? By the way did you lift that example from Dive Into Python ? > > And in my script, there're many 'print' statements.So SOS~~~~ > what should i do??? > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Low Kian Seong Senior Software Manager Logistics Consulting Asia M: +6 012 3736874 ? T: +60 3 7729 9386 ? F: +60 3 7729 7386 www.logisticsconsulting.asia China ? India ? Indonesia ? Malaysia ? Philippines ? Singapore ? Thailand ? Vietnam -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri Feb 18 01:42:55 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 18 Feb 2011 07:42:55 +0100 Subject: Converting getCSS Count Code from java to python In-Reply-To: <1773a6b2-22e1-4ab9-a6d4-47903500069a@a8g2000pri.googlegroups.com> References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> <1773a6b2-22e1-4ab9-a6d4-47903500069a@a8g2000pri.googlegroups.com> Message-ID: SMERSH009, 18.02.2011 07:25: > On Feb 17, 9:51 pm, Stefan Behnel wrote: >> SMERSH009, 17.02.2011 22:46: >>> class Untitled(unittest.TestCase): >>> def count_css_matches(self, css_locator): >>> java_script_code = ''' >>> var cssMatches = eval_css("%s", window.document); >>> cssMatches.length;''' % css_locator >>> return int(selenium.get_eval(self, java_script_code)) >>> #return int(selenium.getEval(java_script_code)) >> >> You want to use "self.selenium" here, not "selenium". > > Wow-- you guys rock --big time! :)) It's just Linus' Law. http://en.wikipedia.org/wiki/Linus%27_Law Stefan From cjns1989 at gmail.com Fri Feb 18 02:05:39 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Fri, 18 Feb 2011 02:05:39 -0500 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <1298010604.11369.6.camel@localhost.localdomain> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <20110218032823.GA29770@pavo.local> <1298010604.11369.6.camel@localhost.localdomain> Message-ID: <20110218070539.GC29770@pavo.local> On Fri, Feb 18, 2011 at 01:30:04AM EST, Westley Mart?nez wrote: > On Thu, 2011-02-17 at 22:28 -0500, Chris Jones wrote: > > On Thu, Feb 17, 2011 at 09:55:47PM EST, Cor Gest wrote: > > > Some entity, AKA Cthun , > > > > [..] > > > > > > And you omitted the #1 most serious objection to Xah's proposal, > > > > rantingrick, which is that to implement it would require unrealistic > > > > things such as replacing every 101-key keyboard with 10001-key > > > > keyboards and training everyone to use them. Xah would have us all > > > > replace our workstations with machines that resemble pipe organs, > > > > rantingrick, or perhaps the cockpits of the three surviving Space > > > > Shuttles. No doubt they'd be enormously expensive, as well as much > > > > more difficult to learn to use, rantingrick. > > > > > At least it should try to mimick a space-cadet keyboard, shouldn't it? > > > > Implementation details, and not very accurate at that.. the APL keyboard > > has not additional keys and yet it has the potential to add up to 100 > > additional symbols to the US-ASCII keyboard, half of which are produced > > via a single modifier.. same as upper-case letters. So unless more than > > 50+20 = 70 symbols are needed the keyboard conversion would cost about.. > > what.. $2.00 in stickers and maybe ten minutes to place them. > > > > Maybe the problem lies elsewhere..? > > > > cj > > > $2.00 * thousands of programmers -> thousands of dollars + thousands > of lost training time; not to mention code conversion. Yeah.. yeah.. one coffee break missed.. get real.. :-) cj From smersh009x at gmail.com Fri Feb 18 02:09:22 2011 From: smersh009x at gmail.com (SMERSH009) Date: Thu, 17 Feb 2011 23:09:22 -0800 (PST) Subject: Converting getCSS Count Code from java to python References: <1667474c-7080-44f8-81a3-c0fb31f41e22@d23g2000prj.googlegroups.com> <1773a6b2-22e1-4ab9-a6d4-47903500069a@a8g2000pri.googlegroups.com> Message-ID: <09dafda2-8aef-4b4c-b1d3-789a234af975@o21g2000prn.googlegroups.com> On Feb 17, 10:25?pm, SMERSH009 wrote: > On Feb 17, 9:51?pm, Stefan Behnel wrote: > > > > > SMERSH009, 17.02.2011 22:46: > > > > am still stuck with the following error when I try to > > > print self.count_css_matches('css=[id="listGuests"]') > > > I've also included the Selenium code below. Any further help would be > > > appreciated. > > > > Traceback (most recent call last): > > > ? ?File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line > > > 27, in test_untitled > > > ? ? ?print self.count_css_matches('css=[id="listGuests"]') > > > ? ?File "D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py", line > > > 17, in count_css_matches > > > ? ? ?return int(selenium.get_eval(self, java_script_code)) > > > TypeError: unbound method get_eval() must be called with selenium > > > instance as first argument (got Untitled instance instead) > > > > ---------------------------------------------------------------------- > > > > from selenium import selenium > > > import unittest, time > > > from datetime import datetime > > > > class Untitled(unittest.TestCase): > > > ? ? ?def count_css_matches(self, css_locator): > > > ? ? ? ? ?java_script_code = ''' > > > ? ? ? ? ? ? ?var cssMatches = eval_css("%s", window.document); > > > ? ? ? ? ? ? ?cssMatches.length;''' % css_locator > > > ? ? ? ? ?return int(selenium.get_eval(self, java_script_code)) > > > ? ? ? ? ?#return int(selenium.getEval(java_script_code)) > > > You want to use "self.selenium" here, not "selenium". > > > Stefan > > > > ? ? ?def setUp(self): > > > ? ? ? ? ?self.verificationErrors = [] > > > ? ? ? ? ?self.selenium = selenium("localhost", 4445, "*chrome", "http:// > > >www.guestlistnation.com/") > > > ? ? ? ? ?self.selenium.start() > > > > ? ? ?def test_untitled(self): > > > ? ? ? ? ?sel = self.selenium > > > ? ? ? ? ?sel.window_maximize() > > > ? ? ? ? ?sel.open("/Events.aspx?Location=SAN FRANCISCO") > > > > sel.click("css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails']") > > > ? ? ? ? ?sel.wait_for_page_to_load("30000") > > > > ? ? ? ? ?print self.count_css_matches('css=[id="listGuests"]') > > > > if __name__ == "__main__": > > > ? ? ?unittest.main() > > Wow-- you guys rock --big time! :)) > Here is the final code with a working examples: > > from selenium import selenium > import unittest, time > from datetime import datetime > > class Untitled(unittest.TestCase): > ? ? def count_css_matches(self, css_locator): > ? ? ? ? java_script_code = ''' > ? ? ? ? ? ? var cssMatches = eval_css("%s", window.document); > ? ? ? ? ? ? cssMatches.length;''' % css_locator > ? ? ? ? return self.selenium.get_eval(java_script_code) > > ? ? def setUp(self): > ? ? ? ? self.verificationErrors = [] > ? ? ? ? self.selenium = selenium("localhost", 4445, "*chrome", "http://www.guestlistnation.com/") > ? ? ? ? self.selenium.start() > > ? ? def test_untitled(self): > ? ? ? ? sel = self.selenium > ? ? ? ? sel.window_maximize() > ? ? ? ? sel.open("/Events.aspx?Location=SAN FRANCISCO") > > sel.click("css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails']") > ? ? ? ? sel.wait_for_page_to_load("30000") > > ? ? ? ? print self.count_css_matches("[id='listGuests'] > option") # > prints number of options in dropdown with 'id=listGuests' > ? ? ? ? print self.count_css_matches("*") #prints all on page > if __name__ == "__main__": > ? ? unittest.main() oops, forgot to put back the int conversion! def count_css_matches(self, css_locator): java_script_code = ''' var cssMatches = eval_css("%s", window.document); cssMatches.length;''' % css_locator return int(self.selenium.get_eval(java_script_code)) From abhijeet.manohar at gmail.com Fri Feb 18 02:42:00 2011 From: abhijeet.manohar at gmail.com (Abhijeet Mahagaonkar) Date: Fri, 18 Feb 2011 13:12:00 +0530 Subject: Help With Tkinter.Checkbutton Widget Message-ID: Dear Pythoners, I have a list of dictionaries. Here i have a variable which should gather input from Checkbutton widget in Tkinter. The Problem that I'm facing is that I'm unable to set or reset the key in every dictionary using the checkbutton widget. Here is what i have been doing. list_of_dict=[{'Flag':0},{'Flag':0}, {'Flag':0}] root=Tkinter.Tk() while i<3: q=Tkinter.IntVar() w=Tkinter.Checkbutton(root, text='Need to include this value?', onvalue=1, offvalue=0, variable=q) w.grid(row=i) list_of_dict[i]['Flag']=q.get() root.mainloop() Could you please let me know what I'm doing wrong? I have tried multiple ways of accomplishing this for eg. by having a command option which will just toggle the list_of_dict[i]['Flag']=not(list[i]['Flag']) Please let me know the best way of doing this. Thanks in advance :) Warm Regards, Abhijeet. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjns1989 at gmail.com Fri Feb 18 02:50:11 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Fri, 18 Feb 2011 02:50:11 -0500 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4d5e0708$0$10591$742ec2ed@news.sonic.net> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> Message-ID: <20110218075011.GD29770@pavo.local> On Fri, Feb 18, 2011 at 12:43:37AM EST, John Nagle wrote: > On 2/17/2011 6:55 PM, Cor Gest wrote: [..] >> At least it should try to mimick a space-cadet keyboard, shouldn't >> it? > I've used both the "MIT Space Cadet" keyboard on a Symbolics LISP > machine, and the Stanford SAIL keyboard. There's something to be > said for having more mathematical symbols. Really..? Wow..! I only every saw pictures of the beast and I was never really convinced it was for real.. :-) > Some programs use a bigger character set. MathCAD, for example, > has a broader range of mathematical symbols on the input side than > ASCII offers. They're not decorative; MathCAD has different "=" > symbols for assignment, algebraic equivalence, identity, and > comparison. Out of curiosity, I played a bit of APL lately, and I was amazed at how quickly you get to learn the extra symbols and their location on the keyboard. Had intergrating the basic concepts of the language been that easy, I would have been comfortably coding within a couple of hours. I was also rather enchanted by the fact that the coding closely matched my intentions. No overloading in this respect. Not that I'm an APL advocate, but who knows what programming languages will look like in the not-so-distant future. > I've previously mentioned that Python suffers in a few places > from unwanted overloading. Using "+" for concatenation of > strings, then extending that to vectors, resulted in undesirable > semantics. "+" on arrays from "numpy", and on built-in vectors > behave quite differently. A dedicated concatenation operator > would have avoided that mess. And the worst part of it is that you get so used to it that you take such matters for granted. Thanks for the eye-opener. > C++ has worse problems, because it uses < and > as both brackets > and operators. This does horrible things to the syntax. .. from a quite different perspective it may be worth noting that practically all programming languages (not to mention the attached documentation) are based on the English language. And interestingly enough, most any software of note appears to have come out of cultures where English is either the native language, or where the native language is either relatively close to English.. Northern Europe mostly.. and not to some small extent, countries where English is well-established as a universal second language, such as India. Always struck me as odd that a country like Japan for instance, with all its achievements in the industrial realm, never came up with one single major piece of software. cj From tjreedy at udel.edu Fri Feb 18 02:54:51 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 18 Feb 2011 02:54:51 -0500 Subject: Unit testing multiprocessing code on Windows In-Reply-To: <4D5DAFEF.8080205@whoosh.ca> References: <4D5DAFEF.8080205@whoosh.ca> Message-ID: On 2/17/2011 6:31 PM, Matt Chaput wrote: > Does anyone know the "right" way to write a unit test for code that uses > multiprocessing on Windows? I would start with Lib/test/test_multiprocessing. -- Terry Jan Reedy From joakim.hove at gmail.com Fri Feb 18 03:29:42 2011 From: joakim.hove at gmail.com (Joakim Hove) Date: Fri, 18 Feb 2011 00:29:42 -0800 (PST) Subject: ctypes from_param() truncating 64 bit pointers to 32 bit Message-ID: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> Hello, I wonder if I am encountering a bug in ctypes; or if I am doing things wrong? I have written a small Python class wrapping a C library, the Python class has a from_param() method which passes a "raw pointer value" from Python to C. When reaching C the pointer has been truncated to 32 bits. I have written a quite extensive post about this on Stackoverflow: http://www.stackoverflow.com/q/5029341/421889/ - so far without response. Would have been very glad if anyone could indicate if this was a bug on my part, or if it is a ctypes bug. I have tried with Python version 2.4 and 2.6 with identical results. Regards Joakim From santiago.caracol at gmail.com Fri Feb 18 03:38:02 2011 From: santiago.caracol at gmail.com (Santiago Caracol) Date: Fri, 18 Feb 2011 00:38:02 -0800 (PST) Subject: reimport module every n seconds References: <6cde71c6-5c56-40ea-9849-50fc44e5decc@o14g2000prb.googlegroups.com> Message-ID: <753e9884-60eb-43cf-a647-12b29ed283a8@y31g2000prd.googlegroups.com> > > Don't do that. ?;-) ?I suggest using exec instead. ?However, I would be > > surprised if import worked faster than, say, JSON (more precisely, I > > doubt that it's enough faster to warrnat this kludge). > > I'm with Aahz. ?Don't do that. > > I don't know what you're doing, but I suspect an even better solution > would be to have your program run a "reconfigure" thread which listens > on a UDP socket and reads a JSON object from it. ?Or, at the very least, > which listens for a signal which kicks it to re-read some JSON from a > disk file. ?This will be more responsive when the data changes quickly > and more efficient when it changes slowly. ?As opposed to just polling > for changes every 10 seconds. Somehow I guessed that I would be told not to do it. But it's my fault. I should have been more explicit. The data is not just data. It is a large set of Django objects I call "ContentClassifiers" that have each certain methods that calculate from user input very large regular expressions. They they have a method "classify" that is applied to messages and uses the very large regular expressions. To classify a message I simply apply the classify method of all ContentClassifiers. There are very many Contentclassifiers. I compile the ContentClassifiers, which are Django objects, to pure Python objects in order to not have to fetch them from the database each time I need them and in order to be able to compile the large regular expressions offline. In Django, I generated and compiled each regular expressions of each ContentClassifier each time I needed it to classify a message. I didn't find a good way to calculate and compile the regular expressions once and store them. I already tested the automatically generated module: Before, classifying a message took about 10 seconds, now it takes miliseconds. My only problem is reloading the module: At the time being, I simply restart the web server manually from time to time in order to load the freshly compiled module. From stefan_ml at behnel.de Fri Feb 18 03:39:10 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 18 Feb 2011 09:39:10 +0100 Subject: ctypes from_param() truncating 64 bit pointers to 32 bit In-Reply-To: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> References: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> Message-ID: Joakim Hove, 18.02.2011 09:29: > I wonder if I am encountering a bug in ctypes; or if I am doing things > wrong? I have written a small Python class wrapping a C library, the > Python class has a from_param() method which passes a "raw pointer > value" from Python to C. When reaching C the pointer has been > truncated to 32 bits. > > I have written a quite extensive post about this on Stackoverflow: > http://www.stackoverflow.com/q/5029341/421889/ - so far without > response. Would have been very glad if anyone could indicate if this > was a bug on my part, or if it is a ctypes bug. I rarely use ctypes and I actually don't know how this specific case works. However, you are not providing a function signature for the "print_addr" C function in the BugTest case, so my guess is that it assumes the standard signature for C functions, which is "int func(int)". That would explain the 32bit truncation. Stefan From joakim.hove at gmail.com Fri Feb 18 03:46:44 2011 From: joakim.hove at gmail.com (Joakim Hove) Date: Fri, 18 Feb 2011 00:46:44 -0800 (PST) Subject: ctypes from_param() truncating 64 bit pointers to 32 bit References: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> Message-ID: <571a8ac7-35af-484d-8cf1-05176431198b@x11g2000yqc.googlegroups.com> Thanks for answering; > I rarely use ctypes You should :-) Apart from my current struggle I think ctypes is really good. > and I actually don't know how this specific case works. > However, you are not providing a function signature for the "print_addr" C > function in the BugTest case, so my guess is that it assumes the standard > signature for C functions, which is "int func(int)". That would explain the > 32bit truncation. Well; I think you are wrong. First of all because what I showed in the Stackoverflow post was just a contrived example - the real code where the problem initially arose does indeed have the proper function signature. Secondly: The use function signatures will be relevant for C-C linkage, but ctypes library only relates to the fully linked shared librarry lib.so where these signatures have been long lost anyway; that is why we have to specify the argtypes and restype attributes of the ctypes function objects?. Joakim From stefan_ml at behnel.de Fri Feb 18 04:49:44 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 18 Feb 2011 10:49:44 +0100 Subject: ctypes from_param() truncating 64 bit pointers to 32 bit In-Reply-To: <571a8ac7-35af-484d-8cf1-05176431198b@x11g2000yqc.googlegroups.com> References: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> <571a8ac7-35af-484d-8cf1-05176431198b@x11g2000yqc.googlegroups.com> Message-ID: Joakim Hove, 18.02.2011 09:46: > Thanks for answering; > >> I rarely use ctypes > > You should :-) Apart from my current struggle I think ctypes is really > good. I'm well aware that it's a very good solution for the cases where you can trade performance for minimizing your external dependencies. But being a Cython developer, those use cases are truly rare for me. >> and I actually don't know how this specific case works. >> However, you are not providing a function signature for the "print_addr" C >> function in the BugTest case, so my guess is that it assumes the standard >> signature for C functions, which is "int func(int)". That would explain the >> 32bit truncation. > > Well; I think you are wrong. Nicely put. > First of all because what I showed in the > Stackoverflow post was just a contrived example - the real code where > the problem initially arose does indeed have the proper function > signature. Ok, then take care to post proper code next time. Details can be important, especially when asking about non-obvious problems. > Secondly:The use function signatures will be > relevant for C-C linkage, but ctypes library only relates to the fully > linked shared librarry lib.so where these signatures have been long > lost anyway; that is why we have to specify the argtypes and restype > attributes of the ctypes function objects?. Hmm, so you think that to call a C function, ctypes doesn't need to know what the exact signature is? That sounds a bit naive to me. It's correct that all compile time information about function signatures is gone in the library. So you must provide ctypes with the exact signature to allow it to convert your input and output data correctly, and to put the values on the call stack in the correct calling layout. Stefan From stefan-usenet at bytereef.org Fri Feb 18 04:55:09 2011 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Fri, 18 Feb 2011 10:55:09 +0100 Subject: ctypes from_param() truncating 64 bit pointers to 32 bit In-Reply-To: <571a8ac7-35af-484d-8cf1-05176431198b@x11g2000yqc.googlegroups.com> References: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> <571a8ac7-35af-484d-8cf1-05176431198b@x11g2000yqc.googlegroups.com> Message-ID: <20110218095509.GA26308@sleipnir.bytereef.org> Joakim Hove wrote: > > and I actually don't know how this specific case works. > > However, you are not providing a function signature for the "print_addr" C > > function in the BugTest case, so my guess is that it assumes the standard > > signature for C functions, which is "int func(int)". That would explain the > > 32bit truncation. > > Well; I think you are wrong. First of all because what I showed in the > Stackoverflow post was just a contrived example - the real code where > the problem initially arose does indeed have the proper function > signature. I suggest that you reconsider, since this appears to work: def from_param(self): return ctypes.c_void_p(self.c_ptr) Stefan Krah From joakim.hove at gmail.com Fri Feb 18 05:10:35 2011 From: joakim.hove at gmail.com (Joakim Hove) Date: Fri, 18 Feb 2011 02:10:35 -0800 (PST) Subject: ctypes from_param() truncating 64 bit pointers to 32 bit References: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> <571a8ac7-35af-484d-8cf1-05176431198b@x11g2000yqc.googlegroups.com> Message-ID: <729788da-14f7-46e8-acc5-72216b0f398c@r12g2000vbd.googlegroups.com> > Ok, then take care to post proper code next time. Details can be important, > especially when asking about non-obvious problems. Point taken - however the original context where the problem arose consists of several massive libraries, which would be quite impractical to post on a forum. The code I did post was proper in the sense that it compiles and demonstrates the problem. > Hmm, so you think that to call a C function, ctypes doesn't need to know > what the exact signature is? That sounds a bit naive to me. I fully agree that ctypes needs to know the type signature of the C functions it wishes to call, my point is that this particular information is not present in the shared library, and for that reason we must set the input / return attributes of the ctypes functions manually. In the Python code I do this like: class BugTest: .... def from_param(self): return self.c_ptr def __init__(self) self.c_ptr = lib_handle = ctypes.CDLL( "lib.so" ) ... func = getattr( lib_handle , "print_addr") # Set the return type: func.restype = None # Set the types of the arguments: func.argtypes = [ BugTest ] Now - the point is that if I omit the ctypes method from_param() and instead set the argtype as: func.argtypes = [ ctypes.c_void_p ] And manually passing the internalized C - pointer to C things work as I expect; I believe that the problem is somewhere along the from_param() function path. I did not make it really clear that if the original C allocation points to memory in "32 bit region" everything works fine (as I expected). Thank you for your time. Joakim From joakim.hove at gmail.com Fri Feb 18 05:15:00 2011 From: joakim.hove at gmail.com (Joakim Hove) Date: Fri, 18 Feb 2011 02:15:00 -0800 (PST) Subject: ctypes from_param() truncating 64 bit pointers to 32 bit References: <67f9d1c0-82ac-48d7-9572-153d3507e406@24g2000yqa.googlegroups.com> <571a8ac7-35af-484d-8cf1-05176431198b@x11g2000yqc.googlegroups.com> Message-ID: <8155b2d8-29e1-436b-abdb-d9f3a79661bd@x13g2000vbe.googlegroups.com> On 18 Feb, 10:55, Stefan Krah wrote: > Joakim Hove wrote: > > > and I actually don't know how this specific case works. > > > However, you are not providing a function signature for the "print_addr" C > > > function in the BugTest case, so my guess is that it assumes the standard > > > signature for C functions, which is "int func(int)". That would explain the > > > 32bit truncation. > > > Well; I think you are wrong. First of all because what I showed in the > > Stackoverflow post was just a contrived example - the real code where > > the problem initially arose does indeed have the proper function > > signature. > > I suggest that you reconsider, since this appears to work: > > ? ? def from_param(self): > ? ? ? ? return ctypes.c_void_p(self.c_ptr) > > Stefan Krah That works - thank you very much! Joakim From steve+comp.lang.python at pearwood.info Fri Feb 18 05:26:02 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Feb 2011 10:26:02 GMT Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> Message-ID: <4d5e493a$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Feb 2011 21:43:37 -0800, John Nagle wrote: > I've used both the "MIT Space Cadet" keyboard on a Symbolics LISP > machine, and the Stanford SAIL keyboard. There's something to be said > for having more mathematical symbols. Agreed. I'd like Python to support proper mathematical symbols like ? for float('inf'), ? for not-equal, ? for greater-than-or-equal, and ? for less-than-or-equal. They would have to be optional, because most editors still make it difficult to enter such characters, and many fonts are lacking in glyphs, but still, now that Python supports non-ASCII encodings in source files, it could be done. > Some programs use a bigger character set. MathCAD, > for example, has a broader range of mathematical symbols on the input > side than ASCII offers. They're not decorative; MathCAD has different > "=" symbols for assignment, algebraic equivalence, identity, and > comparison. > > I've previously mentioned that Python suffers in a few places > from unwanted overloading. Using "+" for concatenation of strings, then > extending that to vectors, resulted in undesirable semantics. "+" on > arrays from "numpy", and on built-in vectors behave quite differently. > A dedicated concatenation operator would have avoided that mess. I don't quite agree that the mess is as large as you make out, but yes, more operators would be useful. -- Steven From steve+comp.lang.python at pearwood.info Fri Feb 18 06:40:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Feb 2011 11:40:17 GMT Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> Message-ID: <4d5e5aa1$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Feb 2011 02:50:11 -0500, Chris Jones wrote: > Always > struck me as odd that a country like Japan for instance, with all its > achievements in the industrial realm, never came up with one single > major piece of software. I think you are badly misinformed. The most widespread operating system in the world is not Windows. It's something you've probably never heard of, from Japan, called TRON. http://www.linuxinsider.com/story/31855.html http://web-japan.org/trends/science/sci030522.html Japan had an ambitious, but sadly failed, "Fifth Generation Computing" project: http://en.wikipedia.org/wiki/Fifth_generation_computer http://vanemden.wordpress.com/2010/08/21/who-killed-prolog/ They did good work, but unfortunately were ahead of their time and the project ended in failure. Japan virtually *owns* the video game market. Yes, yes, Americans publish a few high-profile first-person shooters. For every one of them, there's about a thousand Japanese games that never leave the country. There's no shortages of programming languages which have come out of Japan: http://hopl.murdoch.edu.au/findlanguages.prx?id=jp&which=ByCountry http://no-sword.jp/blog/2006/12/programming-without-ascii.html The one you're most likely to have used or at least know of is Ruby. -- Steven From chris at simplistix.co.uk Fri Feb 18 06:57:47 2011 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 18 Feb 2011 11:57:47 +0000 Subject: mortar_rdb 1.0.0 released! Message-ID: <4D5E5EBB.7030804@simplistix.co.uk> Hi All, I'm very pleased to finally announce the release of mortar_rdb 1.0.0. This package ties together SQLAlchemy, sqlalchemy-migrate and the component architecture to make it easy to develop projects using SQLAlchemy through their complete lifecycle. While I'll be using it with Pyramid, the idea is that it should seamlessly slot into any framework, web or otherwise. I'll be actively helping anyone who runs into problems with their framework of choice. If you'd like to see what mortar_rdb can do for you, please have a read of the narrative usage docs, which give a quick run through of the lifespan of a project developers using mortar_rdb: http://packages.python.org/mortar_rdb/use.html Full package details including mailing list, irc and bug tracker details can be found here: http://www.simplistix.co.uk/software/python/mortar_rdb cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From giacomo.boffi at polimi.it Fri Feb 18 07:02:09 2011 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Fri, 18 Feb 2011 13:02:09 +0100 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> Message-ID: <8662shblfi.fsf@aiuole.stru.polimi.it> Chris Jones writes: > [...] most any software of note appears to have come out of cultures > where English is either the native language, or where the native > language is either relatively close to English... i do acknowledge your "most", but how do you spell "Moon" in Portuguese? From giacomo.boffi at polimi.it Fri Feb 18 07:06:24 2011 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Fri, 18 Feb 2011 13:06:24 +0100 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> <4d5e493a$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <861v35bl8f.fsf@aiuole.stru.polimi.it> Steven D'Aprano writes: >> A dedicated concatenation operator would have avoided that mess. > > I don't quite agree that the mess is as large as you make out, but yes, > more operators would be useful. am i wrong, or "|" is still available? -- l'amore e' un sentimento a senso unico. a volte una via comincia dove finisce un'altra e viceversa -- Caldana, in IFQ From hobson42 at gmail.com Fri Feb 18 07:27:19 2011 From: hobson42 at gmail.com (Ian) Date: Fri, 18 Feb 2011 12:27:19 +0000 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <20110218075011.GD29770@pavo.local> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> <20110218075011.GD29770@pavo.local> Message-ID: <4D5E65A7.9030808@gmail.com> On 18/02/2011 07:50, Chris Jones wrote: > Always > struck me as odd that a country like Japan for instance, with all its > achievements in the industrial realm, never came up with one single > major piece of software. I think there are two reasons for this. 1) Written Japanese is so hard that the effective illiteracy rate in Japan is astonishingly high. Both UK and Japan claim 99% literacy rate, but UK has 10-20% who find reading so hard they don't read. In Japan by some estimates the proportion is about half. Figures from memory. Result - too many users struggle to read instructions and titles on screen. Help texts? Forgetaboutit. 2) Culture. In the West, a designer will decide the architecture of a major system, and it is a basis for debate and progress. If he gets it wrong, it is not a personal disgrace or career limiting. If it is nearly right, then that is a major success. In Japan, the architecture has to be a debated and agreed. This takes ages, costs lots, and ultimately fails. The failure is because architecture is always a trade off - there is no perfect answer. I was involved in one software project where a major Japanese company had done the the feasibility study. It was much much too expensive. The UK company I worked for was able, not only to win the bid, but complete the job profitably for less than the Japanese giant had charged for the feasibility study. We ignored their study - we did not have time to read through the documentation which took 10 foot of shelf space to house. Ian From xahlee at gmail.com Fri Feb 18 07:43:13 2011 From: xahlee at gmail.com (Xah Lee) Date: Fri, 18 Feb 2011 04:43:13 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> Message-ID: <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> On 2011-02-16, Xah Lee ?wrote: ? Vast majority of computer languages use ASCII as its character set. ? This means, it jams multitude of operators into about 20 symbols. ? Often, a symbol has multiple meanings depending on contex. On 2011-02-17, rantingrick wrote: ? On 2011-02-17, Cthun wrote: ? And you omitted the #1 most serious objection to Xah's proposal, ? rantingrick, which is that to implement it would require unrealistic ? things such as replacing every 101-key keyboard with 10001-key keyboards ? and training everyone to use them. Xah would have us all replace our ? workstations with machines that resemble pipe organs, rantingrick, or ? perhaps the cockpits of the three surviving Space Shuttles. No doubt ? they'd be enormously expensive, as well as much more difficult to learn ? to use, rantingrick. keyboard shouldn't be a problem. Look at APL users. http://en.wikipedia.org/wiki/APL_(programming_language) they are happy campers. Look at Mathematica, which support a lot math symbols since v3 (~1997) before unicode became popular. see: ?How Mathematica does Unicode?? http://xahlee.org/math/mathematica_unicode.html word processors, also automatically do symbols such as ?curly quotes?, trade mark sign ?, copyright sing ?, arrow ?, bullet ?, ellipsis ? etc, and the number of people who produce document with these chars are probably more than the number of programers. in emacs, i recently also wrote a mode that lets you easily input few hundred unicode chars. ?Emacs Math Symbols Input Mode (xmsi-mode)? http://xahlee.org/emacs/xmsi-math-symbols-input.html the essence is that you just need a input system. look at Chinese, Japanese, Korean, or Islamic. They happily type without requiring that every symbol they use must have a corresponding key on keyboard. Some lang, such as Chinese, that's impossible or impractical. when a input system is well designd, it could be actually more efficient than keyboard combinations to typo special symbols (such as in Mac OS X's opt key, or Windows's AltGraph). Because a input system can be context based, that it looks at adjacent text to guess what you want. for example, when you type >= in python, the text editor can automatically change it to ? (when it detects that it's appropriate, e.g. there's a ?if? nearby) Chinese phonetic input system use this extensively. Abbrev system in word processors and emacs is also a form of this. I wrote some thought about this here: ?Designing a Math Symbols Input System? http://xahlee.org/comp/design_math_symbol_input.html Xah Lee From peter.mosley at talk21.com Fri Feb 18 07:55:01 2011 From: peter.mosley at talk21.com (peter) Date: Fri, 18 Feb 2011 04:55:01 -0800 (PST) Subject: Archiving Modules References: <9a340d80-ddfd-4985-8b2c-1e4a14e953a9@w21g2000yqm.googlegroups.com> Message-ID: <6f40ae3c-715f-4937-8f43-8a7adc107fd6@j11g2000yqh.googlegroups.com> On Feb 17, 9:55?pm, Jorgen Grahn wrote: > RAR is a proprietary format, which complicates things. For example, > Linux distributions like Debian cannot distribute software which > handles it. ?If Python included such a module, they'd be forced to > remove it from their version. Good point, and one that I did not appreciate. But there are freeware applications such as jzip (http://www.jzip.com) which can handle .rar files, so there must be a way round it. > I wouldn't encourage its use by writing /more/ software which handles > it. IMHO, archives should be widely readable forever, and to be that > they need to be in a widely used, open format. I agree, but if a file is only available as a rar archive I would like to be able to extract it without using another 3rd party application. peter From xahlee at gmail.com Fri Feb 18 08:01:45 2011 From: xahlee at gmail.com (Xah Lee) Date: Fri, 18 Feb 2011 05:01:45 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> Message-ID: Chris Jones wrote: ?.. from a quite different perspective it may be worth noting that practically all programming languages (not to mention the attached documentation) are based on the English language. And interestingly enough, most any software of note appears to have come out of cultures where English is either the native language, or where the native language is either relatively close to English.. Northern Europe mostly.. and not to some small extent, countries where English is well- established as a universal second language, such as India. Always struck me as odd that a country like Japan for instance, with all its achievements in the industrial realm, never came up with one single major piece of software.? btw, english is one of the two of India's official lang. It's used between Indians, and i think it's rare or non-existent for a college in india that uses local dialect. (this is second hand knowledeg. I learned this in Wikipedia and experience with indian co-workers) i also wondered about why japan doesn't seems to have created major software or OS. Though, Ruby is invented in Japan. I do think they have some OSes just not that popular... i think for special purposes OSes, they have quite a lot ... from Mitsubishi, NEC, etc... in their huge robotics industry among others. (again, this is all second hand knowledge) ... i recall having read non-english comp lang that appeared recently... Xah Lee From peterob333 at gmail.com Fri Feb 18 08:41:03 2011 From: peterob333 at gmail.com (peterob) Date: Fri, 18 Feb 2011 05:41:03 -0800 (PST) Subject: email library, get_payload() bug? Message-ID: Helllo, I want to get the raw format of email body. the code Im using is for part in email.walk(): if part.get_content_maintype() == 'multipart': continue if part.get_content_type() == 'text/plain': # print part.get_content_type() print part.get_payload(None,True) The problem is, that code adds one more '\n' at the and of the output printed by get_payload(). Is that bug? Thanks. Best, Peter From steve at fenestra.com Fri Feb 18 08:55:53 2011 From: steve at fenestra.com (Steve Schafer) Date: Fri, 18 Feb 2011 08:55:53 -0500 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> Message-ID: <28usl61q0qul7gfec00bc9840nica4iag8@4ax.com> On Thu, 17 Feb 2011 20:47:57 -0800 (PST), rantingrick wrote: >What is evolution? > >Evolution is the pursuit of perfection at the expense of anything and >everything! No, evolution is the pursuit of something just barely better than what the other guy has. Evolution is about gaining an edge, not gaining perfection. Perfect is the enemy of good. -Steve Schafer From premjee07 at gmail.com Fri Feb 18 09:00:54 2011 From: premjee07 at gmail.com (Free Online Jobs) Date: Fri, 18 Feb 2011 06:00:54 -0800 (PST) Subject: How to Earn Money with FOREX, ., Simple Tricks to Make $1000 per day at HOME .,.,., Message-ID: Earn Fast Online money with FOREX ,.,.,. Free to join,Internet jobs at HOME ,. 24-hrs online support,.,.,. = = = = = = = http://fxtradingmoney.com New and More home based business options to earn MONEY Fast .,.,.,., = = = = = = = = = = = = = = = = = http://fxtradingmoney.com From ricaraoz at gmail.com Fri Feb 18 09:04:18 2011 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Fri, 18 Feb 2011 11:04:18 -0300 Subject: Best way to gain root privileges In-Reply-To: <4d5d9752$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <4d5d9752$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D5E7C62.8030103@gmail.com> On 17/02/2011 06:46 p.m., Steven D'Aprano wrote: > On Thu, 17 Feb 2011 19:44:20 +0000, Katie T wrote: > >> Running any kind of script sudo'd is a bad idea, it's very very hard (in >> many cases impossible) to do securely. Root permissions in general >> should only be used for what they're needed for and nothing else (that >> means getting the permission, doing the stuff that needs to be done as >> root, and then returning back to normal privs), anything else is just >> asking for trouble. > I agree with your general point, but the specific point to avoid running > scripts with sudo? Are you sure you're not conflating sudo with setuid? > By my reading, sudo is far preferred over running scripts setuid root. > > Linux, for example, simply will not run scripts setuid root because of > the security risk, while running things using sudo is considered best > practice, and much preferred over logging in as root. The idea of sudo is > to do exactly what you say: doing the stuff needed as root with elevated > permission, then returning to normal. Maybe this is a bit OT, as it involves the OS and security system, but considering the general knowledge assembled in this list and that it is related to the thread....... I've always asked myself why can't a program be used by users of a certain group but run with the privileges of some other user, not necessarily the one that uses it, but one created specifically for the tasks the program is responsible for. AFAIK in Linux a program will only run with the privileges of the user who runs it. But I can see no reason (other than it is not actually permitted by the OS) that a program can't run with it's *own* privileges. Many a time I have wanted to allow access to certain privileges to a user but *only* through a program. As far as security is concerned it would be enough that only root has permission to give the said program running privileges (privileges different from those of the user that is actually running it), that only allowed users may modify the program, and that *other* users may only run it. This would address the issue of someone modifying the program to gain access to it's privileges. Now, if someone is able to gain illegal privileges to modify the program, then there *is* a security hole and the program is not really the problem. Am I misinformed and you can actually do this in Linux? Am I being naive security wise? From cjns1989 at gmail.com Fri Feb 18 09:06:37 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Fri, 18 Feb 2011 09:06:37 -0500 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4d5e5aa1$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> <4d5e5aa1$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110218140637.GG29770@pavo.local> On Fri, Feb 18, 2011 at 06:40:17AM EST, Steven D'Aprano wrote: > On Fri, 18 Feb 2011 02:50:11 -0500, Chris Jones wrote: > > Always struck me as odd that a country like Japan for instance, with > > all its achievements in the industrial realm, never came up with one > > single major piece of software. > I think you are badly misinformed. > > The most widespread operating system in the world is not Windows. It's > something you've probably never heard of, from Japan, called TRON. > > http://www.linuxinsider.com/story/31855.html > http://web-japan.org/trends/science/sci030522.html > > Japan had an ambitious, but sadly failed, "Fifth Generation Computing" > project: > > http://en.wikipedia.org/wiki/Fifth_generation_computer > http://vanemden.wordpress.com/2010/08/21/who-killed-prolog/ > > They did good work, but unfortunately were ahead of their time and the > project ended in failure. > > Japan virtually *owns* the video game market. Yes, yes, Americans publish > a few high-profile first-person shooters. For every one of them, there's > about a thousand Japanese games that never leave the country. > > There's no shortages of programming languages which have come out of > Japan: > > http://hopl.murdoch.edu.au/findlanguages.prx?id=jp&which=ByCountry > http://no-sword.jp/blog/2006/12/programming-without-ascii.html > > The one you're most likely to have used or at least know of is Ruby. Food for thought.. Thanks much for the links..! cj From cjns1989 at gmail.com Fri Feb 18 09:13:45 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Fri, 18 Feb 2011 09:13:45 -0500 Subject: Problem with giant font sizes in tkinter In-Reply-To: <4d55f20c$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4d538cc1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4d549a01$0$29974$c3e8da3$5496439d@news.astraweb.com> <4d55f20c$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20110218141345.GH29770@pavo.local> On Fri, Feb 11, 2011 at 09:35:56PM EST, Steven D'Aprano wrote: > On Fri, 11 Feb 2011 01:29:02 -0500, Chris Jones wrote: > > >> >> labelfont = '-Adobe-Helvetica-Bold-R-Normal-*-140-*' > > [...] > > First of all, you need to know precisely what the above font name coding > > means. > [...] > > http://www.archive.org/details/xwindowsytemosf03querarch > > Thanks for the link, that's incredibly useful (although the PDF > doesn't render correctly in any of the five different PDF viewers > I tried, but I was able to read it). The O'Reilly X admin guide is also available at the same address and has a few more pieces of the puzzle. Should've mentioned that you should download the (much smaller) *.djvu files rather than the pdf's. Much smaller files, and render considerably faster. The ?evince? viewer on GNU/Linux appears to understand the djvu format. cj From roy at panix.com Fri Feb 18 09:21:51 2011 From: roy at panix.com (Roy Smith) Date: Fri, 18 Feb 2011 09:21:51 -0500 Subject: interrupted system call w/ Queue.get References: Message-ID: In article , Philip Winston wrote: > We have a multiprocess Python program that uses Queue to communicate > between processes. Recently we've seen some errors while blocked > waiting on Queue.get: > > IOError: [Errno 4] Interrupted system call > > What causes the exception? Unix divides system calls up into "slow" and "fast". The difference is how the react to signals. Fast calls are things which are expected to return quickly. A canonical example would get getuid(), which just returns a number it looks up in a kernel data structure. Fast syscalls cannot be interrupted by signals. If a signal arrives while a fast syscall is running, delivery of the signal is delayed until after the call returns. Slow calls are things which may take an indeterminate amount of time to return. An example would be a read on a network socket; it will block until a message arrives, which may be forever. Slow syscalls get interrupted by signals. If a signal arrives while a slow syscall is blocking, the call returns EINTR. This lets your code have a chance to do whatever is appropriate, which might be clean up in preparation for process shutdown, or maybe just ignore the interrupt and re-issue the system call. Here's a short python program which shows how this works (tested on MacOS-10.6, but should be portable to just about any posix box): ----------------------------------------------------- #!/usr/bin/env python import socket import signal import os def handler(sig_num, stack_frame): return print "my pid is", os.getpid() signal.signal(signal.SIGUSR1, handler) s = socket.socket(type=socket.SOCK_DGRAM) s.bind(("127.0.0.1", 0)) s.recv(1024) ----------------------------------------------------- Run this in one window. It should print out its process number, then block on the recv() call. In another window, send it a SIGUSR1. You should get something like: play$ ./intr.py my pid is 6969 Traceback (most recent call last): File "./intr.py", line 14, in s.recv(1024) socket.error: [Errno 4] Interrupted system call > Is it necessary to catch this exception > and manually retry the Queue operation? Thanks. That's a deeper question which I can't answer. My guess is the interrupted system call is the Queue trying to acquire a lock, but there's no predicting what the signal is. I'm tempted to say that it's a bug in Queue that it doesn't catch this exception internally, but people who know more about the Queue implementation than I do should chime in. > We have some Python 2.5 and 2.6 machines that have run this program > for many 1,000 hours with no errors. But we have one 2.5 machine and > one 2.7 machine that seem to get the error very often. Yup, that's the nature of signal delivery race conditions in multithreaded programs. Every machine will behave a little bit differently, with no rhyme or reason. Google "undefined behavior" for more details :-) The whole posix signal delivery mechanism dates back to the earliest Unix implementations, long before there were threads or networks. At this point, it's got many layers of duct tape. From rantingrick at gmail.com Fri Feb 18 09:22:32 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 18 Feb 2011 06:22:32 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> <28usl61q0qul7gfec00bc9840nica4iag8@4ax.com> Message-ID: <3e1fce88-72cc-45d1-b372-024306abc09c@w36g2000vbi.googlegroups.com> On Feb 18, 7:55?am, Steve Schafer wrote: > On Thu, 17 Feb 2011 20:47:57 -0800 (PST), rantingrick > > wrote: > >What is evolution? > > >Evolution is the pursuit of perfection at the expense of anything and > >everything! > > No, evolution is the pursuit of something just barely better than what > the other guy has. You fail to see from a larger perspective. You still see through the eyes of part and not a whole. Each cog that is part of a machine is just a means to an end. You are attempting to elevate one cog above all other cogs, heck, you want to elevate one cog above the machine. You are nothing, and until you accept your nothingness, only then will you understand your place in the greater game. > Evolution is about gaining an edge, not gaining > perfection. Evolution is about one cog gaining an edge over another, yes. However the system itself moves toward perfection at the expense of any and all cogs. > Perfect is the enemy of good. No. Perfect is the enemy of YOU. You are not able to be perfect therefor you claim that perfection is evil to justify your meaningless existence. And who are YOU to weigh good an evil? What do YOU know about the Universe that gives you these powers of judgment? Do you think with your measly 60-100 years of lifetime you can contemplate the meaning of good and evil in a Universe that has existed for eons? Get REAL! We only see and know a small fraction of what the Universe really is. A huge portion of the Universe cannot even be accounted for. And you parade around like some all-knowing being with all the answers and full of selfishness and vanity. Ha! If perfection is evil then what is the pursuit of perfection: AKA: gaining an edge? From askutt at gmail.com Fri Feb 18 09:22:37 2011 From: askutt at gmail.com (Adam Skutt) Date: Fri, 18 Feb 2011 06:22:37 -0800 (PST) Subject: Best way to gain root privileges References: <4d5d9752$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <30a2c06b-1844-48a6-af14-b5a1dc2c62ac@d23g2000prj.googlegroups.com> On Feb 18, 9:04?am, Ricardo Ar?oz wrote: > I've always asked myself why can't a program be used by users of a > certain group but run with the privileges of some other user, not > necessarily the one that uses it, but one created specifically for the > tasks the program is responsible for. > > AFAIK in Linux a program will only run with the privileges of the user > who runs it. This is precisely what the setuid /setgid bits do: force the program to run as the user and group that owns the program, instead of the user / group of the caller. It is forbidden for scripts due to lots of historical problems and inherent difficultly in writing (shell) scripts that can be elevated securely. That being said, it's typically a terrible, horrible idea. The effort involved in ensuring the program cannot be exploited rarely outweighs the gains involved from switching privileges. > Many a time I have wanted to allow access to certain privileges to a user but *only* > through a program. As far as security is concerned it would be enough > that only root has permission to give the said program running > privileges (privileges different from those of the user that is actually > running it), that only allowed users may modify the program, and that > *other* users may only run it. This would address the issue of someone > modifying the program to gain access to it's privileges. Now, if someone > is able to gain illegal privileges to modify the program, then there > *is* a security hole and the program is not really the problem. sudo already does this to a limited degree. If you want more granularity than sudo, you're looking at mandatory access controls. Adam From calderone.jeanpaul at gmail.com Fri Feb 18 09:23:06 2011 From: calderone.jeanpaul at gmail.com (Jean-Paul Calderone) Date: Fri, 18 Feb 2011 06:23:06 -0800 (PST) Subject: interrupted system call w/ Queue.get References: Message-ID: <7037b0b0-fd7e-4853-aea2-57761bb2f715@y31g2000prd.googlegroups.com> On Feb 17, 8:46?pm, Philip Winston wrote: > We have a multiprocess Python program that uses Queue to communicate > between processes. ?Recently we've seen some errors while blocked > waiting on Queue.get: > > IOError: [Errno 4] Interrupted system call > > What causes the exception? ?Is it necessary to catch this exception > and manually retry the Queue operation? ?Thanks. > The exception is caused by a syscall returning EINTR. A syscall will return EINTR when a signal arrives and interrupts whatever that syscall was trying to do. Typically a signal won't interrupt the syscall unless you've installed a signal handler for that signal. However, you can avoid the interruption by using `signal.siginterrupt` to disable interruption on that signal after you've installed the handler. As for the other questions - I don't know, it depends how and why it happens, and whether it prevents your application from working properly. Jean-Paul From gsowww at yahoo.co.uk Fri Feb 18 09:42:30 2011 From: gsowww at yahoo.co.uk (GSO) Date: Fri, 18 Feb 2011 14:42:30 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: On 17 February 2011 18:39, Adam Skutt wrote: ... > As Terry suggests (and I fully concur), all of these issues are best > solved by having a privileged daemon (though it may not need to be > root or entirely root). > I think this could be done more or less with the multiprocessing module: http://docs.python.org/library/multiprocessing.html#module-multiprocessing However I would like to have a look at policykit first, it could be a more elegant solution: http://pypi.python.org/pypi?:action=search&term=polkit&submit=search http://en.wikipedia.org/wiki/PolicyKit http://www.freedesktop.org/wiki/Software/PolicyKit http://ubuntuforums.org/showthread.php?t=1359397 http://live.gnome.org/PolicyKit I note that policykit was created by redhat, and that RHEL6 does not include gksudo in with its gnome for some odd reason. From funthyme at gmail.com Fri Feb 18 09:44:48 2011 From: funthyme at gmail.com (John Pinner) Date: Fri, 18 Feb 2011 06:44:48 -0800 (PST) Subject: Best way to gain root privileges References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: <4751079e-7783-4189-8623-c88e960f9c44@n10g2000yqf.googlegroups.com> On Feb 17, 3:32?pm, GSO wrote: > > I'm having a awfully hard time figuring out why a home CCTV > > application might need privilege at all. ?Are you sure you really need > > privilege? ?It sounds to me like there may be some larger design > > issues mandating the need for privilege when it's not really > > necessary. > > A user login should only able to view the footage. ?It's important > that a user login cannot delete any images/video. ?This much can be > done with ACL - but having said that a user login would still be able > to copy the images/video, so ACL would work but is not ideal - I could > prevent copying with raised privileges. ?If I were to allow a user to > archive footage without using an admin login then that would require > ACL with write access, which is out of the question. Uour origianl questions was: I'm sure this question is as old as time, but what is the best way to gain root privileges? (Am using Python 2.6.5, pygtk2 v2.16, Gtk v2.18.9, on RHEL6.) To which I would say, redesign the app so that you do not need root privileges. There has been plentiful advice in this thread already, but I would add: Now that you've said what the requirement is, why don't you work with the OS instead of against it? Linux and, to a lesser extent, Unix have the ability to set 'setuid', 'setgid' and 'sticky' bits on a directory's permissions, so if, for example the setgid bit is set, then all files created in that directory will belong to the group owning the directory. The sticky bit ensures that only the super user or the file owner may delete a file in the directory. See the chmod manual entry - man chmod - for details. You would need to be root to set this up initially. I think that using this mechanism, together with an appropriate umask or mode setting, should satisfy your requirements, without potential security breakages. Best wishes, John -- From rantingrick at gmail.com Fri Feb 18 09:58:12 2011 From: rantingrick at gmail.com (rantingrick) Date: Fri, 18 Feb 2011 06:58:12 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> <28usl61q0qul7gfec00bc9840nica4iag8@4ax.com> <3e1fce88-72cc-45d1-b372-024306abc09c@w36g2000vbi.googlegroups.com> Message-ID: <8ebe30dd-0e70-4a8d-aef4-96b9c800505f@t19g2000prd.googlegroups.com> On Feb 18, 8:22?am, rantingrick wrote: > > Perfect is the enemy of good. Do you think that just because something has a negative impact towards you (or your existence) that the *something* is then evil? Take a animal for instance: We kill animals for sustenance. The act of killing the animal is negative from the viewpoint of the animal however it does not make the killing evil. Of course if the animal could speak i am sure it will tell you that you are evil for ending its life. However the animal would be speaking from a selfish viewpoint. The animal fails to see that the human is more important than itself in the evolutionary chain. And by consuming the flesh of the animal the human can continue to evolve more knowledge. However the animal's life was not in vain for it's flesh contributed to the life of an intelligent agent who then was able to further the knowledge base of evolution far beyond what the animal could have ever achieved! Likewise *we* as intelligent agents are the tools of an intelligent evolution. When the human becomes insufficient (from the rise of AI) then the human will become the consumable. You are like the animal, not understanding your place in the universe. You fail to see the Universe from OUTSIDE your *own* selfish interpretation. You cannot wield the meanings of good and evil from a selfish and naive interpretation of the Universe. You must look much deeper. "You are not *something* unless you first realize you are *nothing*." From steve at fenestra.com Fri Feb 18 10:01:01 2011 From: steve at fenestra.com (Steve Schafer) Date: Fri, 18 Feb 2011 10:01:01 -0500 Subject: Problems of Symbol Congestion in Computer Languages References: <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> <28usl61q0qul7gfec00bc9840nica4iag8@4ax.com> <3e1fce88-72cc-45d1-b372-024306abc09c@w36g2000vbi.googlegroups.com> Message-ID: On Fri, 18 Feb 2011 06:22:32 -0800 (PST), rantingrick wrote: >Evolution is about one cog gaining an edge over another, yes. However >the system itself moves toward perfection at the expense of any and >all cogs. Um, do you actually know anything about (biological) evolution? There is no evidence of an overall "goal" of any kind, perfect or not. * There are many examples of evolutionary "arms races" in nature; e.g., the cheetah and the gazelle, each gaining incrementally on the other, and a thousand generations later, each in essentially the same place relative to the other that they started from, only with longer legs or a more supple spine. * There are many adaptations that confer a serious DISadvantage in one aspect of survivability, that survive because they confer an advantage in another (sickle-cell disease in humans, a peacock's tail, etc.). >If perfection is evil then what is the pursuit of perfection: AKA: >gaining an edge? 1) I never said that perfection is evil; those are entirely your words. 2) If you don't already see the obvious difference between "pursuit of perfection" and "gaining an edge," then I'm afraid there's nothing I can do or say to help you. -Steve Schafer From cthun_117 at qmail.net.au Fri Feb 18 10:07:43 2011 From: cthun_117 at qmail.net.au (Cthun) Date: Fri, 18 Feb 2011 10:07:43 -0500 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> Message-ID: On 18/02/2011 7:43 AM, Xah Lee wrote: > On 2011-02-17, Cthun wrote: > ? And you omitted the #1 most serious objection to Xah's proposal, > ? rantingrick, which is that to implement it would require unrealistic > ? things such as replacing every 101-key keyboard with 10001-key > keyboards What does your classic unsubstantiated and erroneous claim have to do with Lisp, Lee? From me+list/python at ixokai.io Fri Feb 18 10:08:56 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Fri, 18 Feb 2011 07:08:56 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4D5DEA94.2060207@tysdomain.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <4D5DEA94.2060207@tysdomain.com> Message-ID: <4D5E8B88.4080901@ixokai.io> On 2/17/11 7:42 PM, Littlefield, Tyler wrote: >>My intention was to educate him on the pitfalls of multiplicity. > O. that's what you call that long-winded nonsense? Education? You must > live in America. Can I hazard a guess that your universal language might > be english? Has it not ever occured to you that people take pride in > their language? It is part of their culture. And yet you rant on about > selfishness? This is an old-rant, there's nothing new to it. Rick's racist and imperialistic anti-Unicode rants have all been fully hashed out months if not years ago, Tyler. There's really nothing more to say about it. He doesn't get it. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From jtim.arnold at gmail.com Fri Feb 18 10:23:35 2011 From: jtim.arnold at gmail.com (Tim) Date: Fri, 18 Feb 2011 07:23:35 -0800 (PST) Subject: client server socket interaction (inetd) References: <2bbf94d0-7929-478d-a9c7-2e18de540945@i39g2000prd.googlegroups.com> Message-ID: <30469695-f5f4-468e-b273-fe1681dee06e@y36g2000pra.googlegroups.com> On Feb 17, 6:09?pm, Martin Gregorie wrote: > On Thu, 17 Feb 2011 13:02:08 -0800, Tim wrote: > > But. The server may encounter a problem > > during the process and ask the user for more information like > > 'abort/retry' or something like that. > > Servers never ask the client for information: they are strictly request/ > response handlers. To do what you're asking about, you'll need to change > both the client and server: > > - the client must analyse every response and, if necessary, ask for > ? more input from the user. IMO it would be best to design it so it > ? can accept several commands, with 'quit' being one of them. Either > ? that or all request/response pairs must be designed so that the client > ? can always send a single request, output the result and exit no matter > ? what the server returns. > > - the server must always return a response to every possible request > ? or log a failure reason, preferably to the system log which is > ? /var/log/messages in Linux, and die. The server must thoroughly > ? validate requests and return an adequate error message if errors were > ? found. I'd strongly suggest that every request generates a single > ? (newline terminated?) response message because that makes error > ? detection much easier. If the response is multi-line, send it as a > ? single line, possibly as a comma-separated list, and let the client > ? format it for display > > I tend to precede every request and response message with a fixed length > byte count: this way the recipient process always knows how many bytes to > read and can report errors if the received length is wrong. Using an 'end > of message marker' (NEWLINE unless a message can legally contain internal > newlines) can also be useful. I tend to put an error flag in the response > message because this simplifies the client. I also design all messages to > be plain ASCII because this makes debugging a lot easier. If things > really turn to worms you can use wireshark to watch the traffic and read > it straight off the screen without needing to decode binary values, etc. > So, an invalid request and response might look like this: > > Request: ? "0013,WHOIS,elvis\n" > Response: ?"0030,ERROR,Unknown request: WHOIS\n" > > > The inetd configuration is: > > myservice ?stream tcp nowait root /local/daemon.py daemon.py > > From what I recall about inetd that should be OK - I guess it must be > since you can get one request through, and I assume (you didn't say) that > a second request is also accepted without restarting the server. > > -- > martin@ ? | Martin Gregorie > gregorie. | Essex, UK > org ? ? ? | Thanks for helping me to understand. I don't know if you're familiar with LaTeX, but that's part of what daemon.py calls via subprocess, and that is the underlying process I wanted the user to be able to interact with. When LaTeX encounters a problem it stops processing, asks the user what to do (like abort/retry, kind-of), and does whatever the user says. The daemon.py script handles that okay from the command line, but if I'm understanding you this will be much harder if not impossible to accomplish from a client communicating over a socket. I thought that maybe I needed to fork the socket (somehow) so it could listen after the message is sent, but it looks like it will be more complex. thanks, I'm going to back to reading more on socket programming. --Tim From call.centeris.2011 at gmail.com Fri Feb 18 10:29:47 2011 From: call.centeris.2011 at gmail.com (CENTERIS 2011- Conference on ENTERprise Information Systems) Date: Fri, 18 Feb 2011 15:29:47 +0000 Subject: =?ISO-8859-1?Q?CENTERIS=922011?= | Conference on ENTERprise Information Systems | Call for Papers Message-ID: <20110218155944.E9F14EE9EA@mail.python.org> Please excuse us if you receive this email more than one. We would be very grateful if you could disseminate this call among your research peers and colleagues. ---------- ---------- CENTERIS?2011 | Call for Papers ---------- Conference on ENTERprise Information Systems ---------- Vilamoura, Algarve, Portugal, 2011, 5-7 October ---------- http://centeris.eiswatch.org submission deadline: March 14, 2011 ---------- Dear Professor / Dr., It is our great pleasure to invite you to the CENTERIS?2011 - Conference on ENTERprise Information Systems ? aligning technology, organizations and people. Already in its third edition, CENTERIS?2011 will be held in Vilamoura, Algarve, Portugal, from 5 to 7 October. During this 3-day conference, under the leitmotiv of Enterprise Information Systems, academics, scientists, IT/IS professionals, scientists, managers and solution providers from all over the world will have the opportunity to share experiences, bring new ideas, debate issues, and introduce the latest developments in the largely multidisciplinary field embraced by the Enterprise Information Systems (EIS), from the social, organizational and technological perspectives. All accepted full papers will be published by Springer-Verlag in a CCIS series book (Communications in Computer and Information Science), which is listed in the ISI proceedings index and SCOPUS. Papers can also be accepted as posters, and an extended abstract of it will be published in a book of abstracts (with ISBN) or in a CD-ROM (with ISBN). Authors of selected papers will be invited to extend the paper for possible publication in international journals and in edited books. Submissions will be reviewed on a double-blind review basis. Only original contributions will be accepted. ---------- ---------- Submission Procedure Researchers and practitioners are invited to submit their manuscript electronically at the Conference webpage (http://centeris.eiswatch.org) until March 14, 2011. Submitted papers will be reviewed on a double-blind review basis. ---------- ---------- Important dates Deadline for paper submission: March 14, 2011 Notification of acceptance/rejection: May 20, 2011 Revised version: June 10, 2011 ---------- For more detailed information, please visit http://centeris.eiswatch.org We hope to see you in Portugal. With our best regards, Maria Manuela Cruz-Cunha Jo?o Eduardo Varaj?o ---------- Conference Co-chairs --- Maria Manuela Cruz-Cunha (mcunha at ipca.pt) Polytechnic Institute of C?vado and Ave, Portugal --- Jo?o Eduardo Varaj?o (jvarajao at utad.pt) University of Tr?s-os-Montes e Alto Douro, Portugal ---------- Program Chair --- Philip Powell University of London, UK ---------- Organization Chair --- Ricardo Martinho (ricardo.martinho at ipleira.p) Polytechnic Institute of Leiria, Portugal ---------- Secretariat secretariat at centeris.eiswatch.org ---------- You are receiving this email because of your research activities on the conference topic. To unsubscribe please send an email to secretariat at centeris.eiswatch.org with the subject "Unsubscribe" ---------- From cfp at centeris2011.eiswatch.org Fri Feb 18 10:58:37 2011 From: cfp at centeris2011.eiswatch.org (=?ISO-8859-1?Q?CENTERIS=922011?= | Conference on ENTERprise Information Systems | Call for Papers) Date: Fri, 18 Feb 2011 15:58:37 +0000 Subject: =?ISO-8859-1?Q?CENTERIS=922011?= | Conference on ENTERprise Information Systems | Call for Papers Message-ID: <20110218162943.F1554EE982@mail.python.org> Please excuse us if you receive this email more than one. We would be very grateful if you could disseminate this call among your research peers and colleagues. ---------- ---------- CENTERIS?2011 | Call for Papers ---------- Conference on ENTERprise Information Systems ---------- Vilamoura, Algarve, Portugal, 2011, 5-7 October ---------- http://centeris.eiswatch.org submission deadline: March 14, 2011 ---------- Dear Professor / Dr., It is our great pleasure to invite you to the CENTERIS?2011 - Conference on ENTERprise Information Systems ? aligning technology, organizations and people. Already in its third edition, CENTERIS?2011 will be held in Vilamoura, Algarve, Portugal, from 5 to 7 October. During this 3-day conference, under the leitmotiv of Enterprise Information Systems, academics, scientists, IT/IS professionals, scientists, managers and solution providers from all over the world will have the opportunity to share experiences, bring new ideas, debate issues, and introduce the latest developments in the largely multidisciplinary field embraced by the Enterprise Information Systems (EIS), from the social, organizational and technological perspectives. All accepted full papers will be published by Springer-Verlag in a CCIS series book (Communications in Computer and Information Science), which is listed in the ISI proceedings index and SCOPUS. Papers can also be accepted as posters, and an extended abstract of it will be published in a book of abstracts (with ISBN) or in a CD-ROM (with ISBN). Authors of selected papers will be invited to extend the paper for possible publication in international journals and in edited books. Submissions will be reviewed on a double-blind review basis. Only original contributions will be accepted. ---------- ---------- Submission Procedure Researchers and practitioners are invited to submit their manuscript electronically at the Conference webpage (http://centeris.eiswatch.org) until March 14, 2011. Submitted papers will be reviewed on a double-blind review basis. ---------- ---------- Important dates Deadline for paper submission: March 14, 2011 Notification of acceptance/rejection: May 20, 2011 Revised version: June 10, 2011 ---------- For more detailed information, please visit http://centeris.eiswatch.org We hope to see you in Portugal. With our best regards, Maria Manuela Cruz-Cunha Jo?o Eduardo Varaj?o ---------- Conference Co-chairs --- Maria Manuela Cruz-Cunha (mcunha at ipca.pt) Polytechnic Institute of C?vado and Ave, Portugal --- Jo?o Eduardo Varaj?o (jvarajao at utad.pt) University of Tr?s-os-Montes e Alto Douro, Portugal ---------- Program Chair --- Philip Powell University of London, UK ---------- Organization Chair --- Ricardo Martinho (ricardo.martinho at ipleira.p) Polytechnic Institute of Leiria, Portugal ---------- Secretariat secretariat at centeris.eiswatch.org ---------- You are receiving this email because of your research activities on the conference topic. To unsubscribe please send an email to secretariat at centeris.eiswatch.org with the subject "Unsubscribe" ---------- From martin at address-in-sig.invalid Fri Feb 18 11:49:36 2011 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Fri, 18 Feb 2011 16:49:36 +0000 (UTC) Subject: client server socket interaction (inetd) References: <2bbf94d0-7929-478d-a9c7-2e18de540945@i39g2000prd.googlegroups.com> <30469695-f5f4-468e-b273-fe1681dee06e@y36g2000pra.googlegroups.com> Message-ID: On Fri, 18 Feb 2011 07:23:35 -0800, Tim wrote: > Thanks for helping me to understand. I don't know if you're familiar > with LaTeX, but that's part of what daemon.py calls via subprocess, and > that is the underlying process I wanted the user to be able to interact > with. > I've used nroff but never LaTeX - however, my understanding is that its essentially a batch process. > When LaTeX encounters a problem it stops processing, asks the user what > to do (like abort/retry, kind-of), and does whatever the user says. The > daemon.py script handles that okay from the command line, but if I'm > understanding you this will be much harder if not impossible to > accomplish from a client communicating over a socket. > Are you sure it wouldn't be better to end the run, returning suitable error messages to the user, who would correct the input file(s) and rerun LaTex? > I thought that maybe I needed to fork the socket (somehow) so it could > listen after the message is sent, but it looks like it will be more > complex. > The easier way my be to give the user a login to a captive shell that's restricted to running LateX, an editor and little else apart from a results viewer. Bash and most decent editors can be restricted so the user can't start a second, less restricted shell, and the range of programs it can execute can be restricted by adjusting with $PATH. You may also be able to find a menu program that can impose many of those restrictions by replacing the login's shell by the menu program. I do this as a matter of course: my menu program may get released one of these days but it's not currently on a fit state to publish. If you want to continue down the server path you should investigate popen. It is part of the os module. You could design the server so a suitable request runs LaTeX via popen, captures the stdout and stderr output, if any, and returns that and the LaTeX termination status code to the client as a response message. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From torriem at gmail.com Fri Feb 18 11:54:02 2011 From: torriem at gmail.com (Michael Torrie) Date: Fri, 18 Feb 2011 09:54:02 -0700 Subject: Newbie getting desperate with for In-Reply-To: References: Message-ID: <4D5EA42A.9090004@gmail.com> On 02/17/2011 04:10 PM, Werner wrote: > It is meant to put load on a CPU, RAM and disk (swap). The code now > looks like this: > #!/usr/bin/python > while True: > i = 0 > for i in range(20000000): > break Just for your information, your code is the equivalent of: while True: temp = range(20000000) The for loop does absolutely nothing in your case. After the range is computed, the for loop exits on the first iteration. On python 3.0 range() is a generator so your code essentially distills down to this if you ran it on python 3: while True: pass From torriem at gmail.com Fri Feb 18 11:55:09 2011 From: torriem at gmail.com (Michael Torrie) Date: Fri, 18 Feb 2011 09:55:09 -0700 Subject: Newbie getting desperate with for In-Reply-To: <48qdnZ28pcPgb8DQnZ2dnUVZ5q6dnZ2d@giganews.com> References: <48qdnZ28pcPgb8DQnZ2dnUVZ5q6dnZ2d@giganews.com> Message-ID: <4D5EA46D.9080702@gmail.com> On 02/17/2011 09:15 PM, Larry Hudson wrote: > A true time waster indeed -- it's an infinite loop that will _never_ end. > > Others have already about the need of the shebang line to run as a python script, but I'm > surprised no one mentioned how truly useless this code is. > > The i = 0 line is totally unnecessary. The variable i is created and set to zero by the first > iteration of the for loop. The break will abort the for loop (NOT the while loop) in the first > iteration, and the 2nd through the 10th iterations will be skipped altogether. To be fair the range() call will be fairly time and memory-consuming on python 2, since it returns a list. > > This effectively leaves your code as: > > while True: > pass # Do nothing, forever > > An empty loop as a time delay can occasionally be useful, but as a practical matter, a for loop > with only 10 (empty/pass) iterations is probably too short for anything useful. Instead of > being empty, do some more complex (but ignored) operation -- say math.sqrt() or math.sin() for > example -- and a much larger repetition count. But it's likely that does use up processor > cycles unnecessarily, although it can give you delays of fractions of seconds. If you want > delays greater than a second, check out the time.sleep() function. > > -=- Larry -=- From matt at whoosh.ca Fri Feb 18 12:05:41 2011 From: matt at whoosh.ca (Matt Chaput) Date: Fri, 18 Feb 2011 12:05:41 -0500 Subject: Unit testing multiprocessing code on Windows In-Reply-To: References: <4D5DAFEF.8080205@whoosh.ca> Message-ID: <4D5EA6E5.9080807@whoosh.ca> On 18/02/2011 2:54 AM, Terry Reedy wrote: > On 2/17/2011 6:31 PM, Matt Chaput wrote: >> Does anyone know the "right" way to write a unit test for code that uses >> multiprocessing on Windows? > > I would start with Lib/test/test_multiprocessing. Good idea, but on the one hand it doesn't seem to be doing anything special, and on the other hand it seems to do it's own things like not having its test cases inherit from unittest.TestCase. I also don't know if the Python devs start it with distutils or nosetests, which are the ones I'm having a problem with. For example, starting my test suite inside PyDev doesn't show the bug. My test code isn't doing anything unusual... this is pretty much all I do to trigger the bug. (None of the imported code has anything to do with processes.) from __future__ import with_statement import unittest import random from whoosh import fields, query from whoosh.support.testing import TempIndex try: import multiprocessing except ImportError: multiprocessing = None if multiprocessing: class MPFCTask(multiprocessing.Process): def __init__(self, storage, indexname): multiprocessing.Process.__init__(self) self.storage = storage self.indexname = indexname def run(self): ix = self.storage.open_index(self.indexname) with ix.searcher() as s: r = s.search(query.Every(), sortedby="key", limit=None) result = "".join([h["key"] for h in r]) assert result == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", result class TestSorting(unittest.TestCase): def test_mp_fieldcache(self): if not multiprocessing: return schema = fields.Schema(key=fields.KEYWORD(stored=True)) with TempIndex(schema, "mpfieldcache") as ix: domain = list(u"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") random.shuffle(domain) w = ix.writer() for char in domain: w.add_document(key=char) w.commit() tasks = [MPFCTask(ix.storage, ix.indexname) for _ in xrange(4)] for task in tasks: task.start() for task in tasks: task.join() if __name__ == '__main__': unittest.main() From enalicho at gmail.com Fri Feb 18 12:06:09 2011 From: enalicho at gmail.com (Noah Hall) Date: Fri, 18 Feb 2011 17:06:09 +0000 Subject: Newbie getting desperate with for In-Reply-To: <4D5EA42A.9090004@gmail.com> References: <4D5EA42A.9090004@gmail.com> Message-ID: On Fri, Feb 18, 2011 at 4:54 PM, Michael Torrie wrote: > On 02/17/2011 04:10 PM, Werner wrote: > Just for your information, your code is the equivalent of: > > while True: > ? ?temp = range(20000000) > > The for loop does absolutely nothing in your case. ?After the range is > computed, the for loop exits on the first iteration. Ah, but the for loop is there for a reason, I imagine. It'd certainly be slower per while loop. From matt at whoosh.ca Fri Feb 18 12:10:34 2011 From: matt at whoosh.ca (Matt Chaput) Date: Fri, 18 Feb 2011 12:10:34 -0500 Subject: Unit testing multiprocessing code on Windows Message-ID: <4D5EA80A.5090407@whoosh.ca> On 17/02/2011 8:22 PM, philip at semanchuk.com wrote: > Hi Matt, > I assume you're aware of this documentation, especially the item > entitled "Safe importing of main module"? > > http://docs.python.org/release/2.6.6/library/multiprocessing.html#windows Yes, but the thing is my code isn't __main__, my unittest classes are being loaded by setup.py test or nosetests. And while I'm assured multiprocessing doesn't duplicate the original command line, what I get sure looks like it, because if I use "python setup.py test" that command seems to be re-run for every Process that starts, but if I use "nosetests" then *that* seems to be re-run for every Process. Matt From wdahn at netfront.net Fri Feb 18 12:48:28 2011 From: wdahn at netfront.net (Werner) Date: Sat, 19 Feb 2011 01:48:28 +0800 Subject: Newbie getting desperate with for In-Reply-To: References: <20110217214037.GA25438@cskk.homeip.net> Message-ID: On 18/02/11 07:29, Cameron Simpson wrote: > On 18Feb2011 08:40, I wrote: > | On 17Feb2011 18:40, Alister Ware wrote: > | | On Thu, 17 Feb 2011 16:42:05 +0800, Werner wrote: > | | > On 17/02/11 16:39, Chris Rebert wrote: > | | >> On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: > | | >>> I have a trivially simple piece of code called timewaster.py: > | | >>> ____________________________________________________ > | | >>> while True: > | [...] > | | may I ask what is the purpose of this code segment, it does not look like > | | it would achieve much? > [... long shebang description...] > > Hmm, looks like maybe you meant the original python snippet. > If so, my apologies for the long misanswer. It was't a misanswer, you were laying a finger on the wound and explained how things are. I am very grateful for that. This is my first contact with this newsgroup and I thank you all for being patient and understanding with a newbie. Best Regards Werner Dahn From anikom15 at gmail.com Fri Feb 18 13:51:59 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 18 Feb 2011 10:51:59 -0800 Subject: Archiving Modules In-Reply-To: <6f40ae3c-715f-4937-8f43-8a7adc107fd6@j11g2000yqh.googlegroups.com> References: <9a340d80-ddfd-4985-8b2c-1e4a14e953a9@w21g2000yqm.googlegroups.com> <6f40ae3c-715f-4937-8f43-8a7adc107fd6@j11g2000yqh.googlegroups.com> Message-ID: <1298055119.13025.0.camel@localhost.localdomain> On Fri, 2011-02-18 at 04:55 -0800, peter wrote: > On Feb 17, 9:55 pm, Jorgen Grahn wrote: > > > > RAR is a proprietary format, which complicates things. For example, > > Linux distributions like Debian cannot distribute software which > > handles it. If Python included such a module, they'd be forced to > > remove it from their version. > > Good point, and one that I did not appreciate. But there are freeware > applications such as jzip (http://www.jzip.com) which can handle .rar > files, so there must be a way round it. > > > I wouldn't encourage its use by writing /more/ software which handles > > it. IMHO, archives should be widely readable forever, and to be that > > they need to be in a widely used, open format. > > I agree, but if a file is only available as a rar archive I would like > to be able to extract it without using another 3rd party application. > > peter Freeware is still proprietary software. From anikom15 at gmail.com Fri Feb 18 14:16:30 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 18 Feb 2011 11:16:30 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> Message-ID: <1298056590.13025.16.camel@localhost.localdomain> On Fri, 2011-02-18 at 04:43 -0800, Xah Lee wrote: > On 2011-02-16, Xah Lee wrote: > ? Vast majority of computer languages use ASCII as its character set. > ? This means, it jams multitude of operators into about 20 symbols. > ? Often, a symbol has multiple meanings depending on contex. > > On 2011-02-17, rantingrick wrote: > ? > > On 2011-02-17, Cthun wrote: > ? And you omitted the #1 most serious objection to Xah's proposal, > ? rantingrick, which is that to implement it would require unrealistic > ? things such as replacing every 101-key keyboard with 10001-key > keyboards > ? and training everyone to use them. Xah would have us all replace our > ? workstations with machines that resemble pipe organs, rantingrick, > or > ? perhaps the cockpits of the three surviving Space Shuttles. No doubt > ? they'd be enormously expensive, as well as much more difficult to > learn > ? to use, rantingrick. > > keyboard shouldn't be a problem. > > Look at APL users. > http://en.wikipedia.org/wiki/APL_(programming_language) > they are happy campers. > > Look at Mathematica, which support a lot math symbols since v3 (~1997) > before unicode became popular. > see: > ?How Mathematica does Unicode?? > http://xahlee.org/math/mathematica_unicode.html > > word processors, also automatically do symbols such as ?curly quotes?, > trade mark sign ?, copyright sing ?, arrow ?, bullet ?, ellipsis ? > etc, and the number of people who produce document with these chars > are probably more than the number of programers. > > in emacs, i recently also wrote a mode that lets you easily input few > hundred unicode chars. > ?Emacs Math Symbols Input Mode (xmsi-mode)? > http://xahlee.org/emacs/xmsi-math-symbols-input.html > > the essence is that you just need a input system. > > look at Chinese, Japanese, Korean, or Islamic. They happily type > without requiring that every symbol they use must have a corresponding > key on keyboard. Some lang, such as Chinese, that's impossible or > impractical. > > when a input system is well designd, it could be actually more > efficient than > keyboard combinations to typo special symbols (such as in Mac OS X's > opt key, or > Windows's AltGraph). Because a input system can be context based, that > it looks > at adjacent text to guess what you want. > > for example, when you type >= in python, the text editor can > automatically change it to ? (when it detects that it's appropriate, > e.g. there's a ?if? nearby) > > Chinese phonetic input system use this > extensively. Abbrev system in word processors and emacs is also a form > of > this. I wrote some thought about this here: > > ?Designing a Math Symbols Input System? > http://xahlee.org/comp/design_math_symbol_input.html > > Xah Lee More people despise APL than like it. Allowing non-ascii characters as operators is a silly idea simply because if xorg breaks, which it's very likely to do with the current video drivers, I'm screwed. Not only does the Linux virtual terminal not support displaying these special characters, but there's also no way of inputting them. On top of that, these special characters require more bytes to display than ascii text, which would bloat source files unnecessarily. You say we have symbol congestion, but in reality we have our own symbol bloat. Japanese has more or less than three punctuation marks, while English has perhaps more than the alphabet! The fundamental point here is using non-ascii operators violates the Zen of Python. It violates "Simple is better than complex," as well as "There should be one-- and preferably only one --obvious way to do it." From zambr123 at not_an_email_address Fri Feb 18 14:18:20 2011 From: zambr123 at not_an_email_address (zambr123) Date: 18 Feb 2011 19:18:20 GMT Subject: Closures in metaclasses Message-ID: <4d5ec5fc$0$23542$c3e8da3$c8fb9443@news.astraweb.com> Hi there, We are currently looking for someone who has ideally several years coding experience, and who is familar with Network coding and the Python language. The project revolves around emulation and a chat based system, altough the vast majority of the project is focused on the chat based system itself. This should prove to be a very fun and rewarding project, and anyone thats able to spare their time to assist, would be greatly appreciated indeed. If you are interested, please contact Jason "Digital Ghost" via his blog http://10ghost.blogspot.com/ On behalf of the Team, Thankyou Zambr123 (Project Software Tester and GUI Designer) From anikom15 at gmail.com Fri Feb 18 14:20:20 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 18 Feb 2011 11:20:20 -0800 Subject: Python Path registry Key In-Reply-To: References: Message-ID: <1298056820.13025.17.camel@localhost.localdomain> On Fri, 2011-02-18 at 11:56 +0530, Sathish S wrote: > Hi Ppl, > > > I'm trying to launch IDLE from another application. For this I need > the python directory path. I have been trying to get the Active Python > versions path from the Windows registry. However, these registry > entries seem not be consistent across various stations, that i > checked. I'm reading the following resitry key to get the active > versions path: Software\\Microsoft\\Windows\\CurrentVersion\\App Paths > \\Python.exe. There are two entries in this key. Some stations have > only one entry. Some do not have both. Probably they were removed > while python was uninstall ed and was not added again when it was > installed again. > > > So what will be a good solution to get the Python path ? > > > > Thanks, > Sathish > Try sys.prefix From zambr123 at not_an_email_address Fri Feb 18 14:24:03 2011 From: zambr123 at not_an_email_address (zambr123) Date: 18 Feb 2011 19:24:03 GMT Subject: Open InvitationTo Join Fun Python based Project Message-ID: <4d5ec753$0$19173$c3e8da3$47a2c32d@news.astraweb.com> Sorry, for the double post, was not intended. Because of wrong subject name ! Hi there, We are currently looking for someone who has ideally several years coding experience, and who is familar with Network coding and the Python language. The project revolves around emulation and a chat based system, altough the vast majority of the project is focused on the chat based system itself. This should prove to be a very fun and rewarding project, and anyone thats able to spare their time to assist, would be greatly appreciated indeed. If you are interested, please contact Jason "Digital Ghost" via his blog http://10ghost.blogspot.com/ On behalf of the Team, Thankyou Zambr123 (Project Software Tester and GUI Designer) From alex.kapps at web.de Fri Feb 18 15:16:35 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Fri, 18 Feb 2011 21:16:35 +0100 Subject: Archiving Modules In-Reply-To: <1298055119.13025.0.camel@localhost.localdomain> References: <9a340d80-ddfd-4985-8b2c-1e4a14e953a9@w21g2000yqm.googlegroups.com> <6f40ae3c-715f-4937-8f43-8a7adc107fd6@j11g2000yqh.googlegroups.com> <1298055119.13025.0.camel@localhost.localdomain> Message-ID: <4D5ED3A3.9040503@web.de> On 18.02.2011 19:51, Westley Mart?nez wrote: > On Fri, 2011-02-18 at 04:55 -0800, peter wrote: >> On Feb 17, 9:55 pm, Jorgen Grahn wrote: >> >> >>> RAR is a proprietary format, which complicates things. For example, >>> Linux distributions like Debian cannot distribute software which >>> handles it. If Python included such a module, they'd be forced to >>> remove it from their version. >> >> Good point, and one that I did not appreciate. But there are freeware >> applications such as jzip (http://www.jzip.com) which can handle .rar >> files, so there must be a way round it. >> >>> I wouldn't encourage its use by writing /more/ software which handles >>> it. IMHO, archives should be widely readable forever, and to be that >>> they need to be in a widely used, open format. >> >> I agree, but if a file is only available as a rar archive I would like >> to be able to extract it without using another 3rd party application. >> >> peter > Freeware is still proprietary software. While I agree with the general refusal of .rar or other non-free archive formats, a useful archiving tool should still be able to extract them. Creating them is an other issue. There is a free (open source) un-rar for Linux which AFAIK can at least handle .rar archives below v3. HTH From alex.kapps at web.de Fri Feb 18 15:21:15 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Fri, 18 Feb 2011 21:21:15 +0100 Subject: Best way to gain root privileges In-Reply-To: <30a2c06b-1844-48a6-af14-b5a1dc2c62ac@d23g2000prj.googlegroups.com> References: <4d5d9752$0$29972$c3e8da3$5496439d@news.astraweb.com> <30a2c06b-1844-48a6-af14-b5a1dc2c62ac@d23g2000prj.googlegroups.com> Message-ID: <4D5ED4BB.8090700@web.de> On 18.02.2011 15:22, Adam Skutt wrote: > On Feb 18, 9:04 am, Ricardo Ar?oz wrote: > >> Many a time I have wanted to allow access to certain privileges to a user but *only* >> through a program. As far as security is concerned it would be enough >> that only root has permission to give the said program running >> privileges (privileges different from those of the user that is actually >> running it), that only allowed users may modify the program, and that >> *other* users may only run it. This would address the issue of someone >> modifying the program to gain access to it's privileges. Now, if someone >> is able to gain illegal privileges to modify the program, then there >> *is* a security hole and the program is not really the problem. > > sudo already does this to a limited degree. If you want more > granularity than sudo, you're looking at mandatory access controls. > > Adam IIUC, than SELinux can also help, since it allows program-specific permissions. But I could easily be wrong here since I have yet to really learn SElinux. From alex.kapps at web.de Fri Feb 18 15:23:51 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Fri, 18 Feb 2011 21:23:51 +0100 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> Message-ID: <4D5ED557.3050006@web.de> On 18.02.2011 15:42, GSO wrote: > I note that policykit was created by redhat, and that RHEL6 does not > include gksudo in with its gnome for some odd reason. Don't know if this helps you, but at least for CentOS 5.4, gksudo is available in the gksu package from rpmforge. From gsowww at yahoo.co.uk Fri Feb 18 15:43:37 2011 From: gsowww at yahoo.co.uk (GSO) Date: Fri, 18 Feb 2011 20:43:37 +0000 Subject: Best way to gain root privileges In-Reply-To: <4D5ED4BB.8090700@web.de> References: <4d5d9752$0$29972$c3e8da3$5496439d@news.astraweb.com> <30a2c06b-1844-48a6-af14-b5a1dc2c62ac@d23g2000prj.googlegroups.com> <4D5ED4BB.8090700@web.de> Message-ID: On 18 February 2011 20:21, Alexander Kapps wrote: ... > IIUC, than SELinux can also help, since it allows program-specific > permissions. But I could easily be wrong here since I have yet to really > learn SElinux. Who has, LOL! If you could post a (very very) quick 'I don't have a PhD in computer security' guide I'm sure we'd all be very grateful :) From xrgtn at yandex.ru Fri Feb 18 16:59:44 2011 From: xrgtn at yandex.ru (Alexander Gattin) Date: Fri, 18 Feb 2011 23:59:44 +0200 Subject: IMAP4_SSL, libgmail, GMail and corporate firewall/proxy In-Reply-To: References: <1297925076.8054.1421127991@webmail.messagingengine.com> <1297952429.21461.1421183197@webmail.messagingengine.com> Message-ID: <20110218215944.GB802@xrgtn-q40> Hello, On Fri, Feb 18, 2011 at 09:40:19AM +0500, Andrea Gavana wrote: > Fails with a variety of errors depending on which port I use: > > - Port 80: urllib2.HTTPError: HTTP Error 407: Proxy Authentication > Required ( The ISA Server requires authorization to fulfill the > request. Access to the Web Proxy filter is denied. ) Wow, that's much better! So your python proxy is working but just doesn't know how to authenticate. Unfortunately I don't remember how to specify proxy auth in python, but this is definitely achievable. Please 1st make ports 80 and 443 working, then you can try IMAP and other ports. In general, you're out of luck if your corporate proxy only supports connecting to ports 80 and 443 in outside world. But if you own a box in the wild, you can setup ssh/openvpn/socks server/whatever on port 443 on that box and use it as a kind of access broker to the rest of ports in the world. -- With best regards, xrgtn From gsowww at yahoo.co.uk Fri Feb 18 17:26:39 2011 From: gsowww at yahoo.co.uk (GSO) Date: Fri, 18 Feb 2011 22:26:39 +0000 Subject: Best way to gain root privileges In-Reply-To: <4D5ED557.3050006@web.de> References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> <4D5ED557.3050006@web.de> Message-ID: On 18 February 2011 20:23, Alexander Kapps wrote: ... > Don't know if this helps you, but at least for CentOS 5.4, gksudo is > available in the gksu package from rpmforge. It looks as though policykit includes similar functionality, namely the command pkexec replaces gksudo: http://hal.freedesktop.org/docs/polkit/pkexec.1.html http://hal.freedesktop.org/docs/polkit/polkit.8.html http://www.freedesktop.org/wiki/Software/PolicyKit A python package: http://pypi.python.org/pypi?:action=search&term=polkit&submit=search But there is example python code here: http://hal.freedesktop.org/docs/polkit/polkit-apps.html I'm still not clear exactly how this works but will post some code once I figure it out. From nobody at nowhere.com Fri Feb 18 17:28:02 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 18 Feb 2011 22:28:02 +0000 Subject: client server socket interaction (inetd) References: <2bbf94d0-7929-478d-a9c7-2e18de540945@i39g2000prd.googlegroups.com> <30469695-f5f4-468e-b273-fe1681dee06e@y36g2000pra.googlegroups.com> Message-ID: On Fri, 18 Feb 2011 07:23:35 -0800, Tim wrote: > When LaTeX encounters a problem it stops processing, asks the user > what to do (like abort/retry, kind-of), and does whatever the user > says. The daemon.py script handles that okay from the command line, > but if I'm understanding you this will be much harder if not > impossible to accomplish from a client communicating over a socket. The difficulty of achieving this is unrelated to the use of a socket. It's an issue of whether you have a user available to respond to any prompts, or whether the client has to be able to do this itself. If you want to "script" an interactive program, you need to be able to recognise prompts and respond appropriately. If the program was designed to interact with a human, this can be far from straightforward. But the method of communication (pipes versus sockets) isn't relevant. From xrgtn at yandex.ru Fri Feb 18 17:33:53 2011 From: xrgtn at yandex.ru (Alexander Gattin) Date: Sat, 19 Feb 2011 00:33:53 +0200 Subject: Connecting to remote Oracle db via Python In-Reply-To: <1e4f8836-20ff-4317-8c30-047ef6ec0c71@4g2000yqo.googlegroups.com> References: <1e4f8836-20ff-4317-8c30-047ef6ec0c71@4g2000yqo.googlegroups.com> Message-ID: <20110218223029.GC802@xrgtn-q40> Hello, On Thu, Feb 17, 2011 at 02:40:22AM -0800, pstatham wrote: > I've installed the cx_Oracle module for Python > and I'm trying to connect to my remote Oracle > db. Can you tnsping your remote Oracle DB successfully? > >>> uid = "scott" > >>> pwd = "tiger" > >>> service = "10.5.1.12:1521:PR10" > >>> db = cx_Oracle.connect(uid + "/" + pwd + "@" + service) Try 'tnsping service' or 'sqlplus uid/pwd at service' in your Korn/Bourne/whoever shell 1st. If this works, then cx_Oracle will work too. 'service' must be specified in system TNSNAMES file or in your ~/.tnsnames.ora -- With best regards, xrgtn From grahn+nntp at snipabacken.se Fri Feb 18 18:52:15 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 18 Feb 2011 23:52:15 GMT Subject: Archiving Modules References: <9a340d80-ddfd-4985-8b2c-1e4a14e953a9@w21g2000yqm.googlegroups.com> <6f40ae3c-715f-4937-8f43-8a7adc107fd6@j11g2000yqh.googlegroups.com> <1298055119.13025.0.camel@localhost.localdomain> Message-ID: On Fri, 2011-02-18, Alexander Kapps wrote: > On 18.02.2011 19:51, Westley Mart?nez wrote: >> On Fri, 2011-02-18 at 04:55 -0800, peter wrote: >>> On Feb 17, 9:55 pm, Jorgen Grahn wrote: >>> >>> >>>> RAR is a proprietary format, which complicates things. For example, >>>> Linux distributions like Debian cannot distribute software which >>>> handles it. If Python included such a module, they'd be forced to >>>> remove it from their version. >>> >>> Good point, and one that I did not appreciate. But there are freeware >>> applications such as jzip (http://www.jzip.com) which can handle .rar >>> files, so there must be a way round it. >>> >>>> I wouldn't encourage its use by writing /more/ software which handles >>>> it. IMHO, archives should be widely readable forever, and to be that >>>> they need to be in a widely used, open format. >>> >>> I agree, but if a file is only available as a rar archive I would like >>> to be able to extract it without using another 3rd party application. >>> >>> peter >> Freeware is still proprietary software. It can be ("freeware" is a vague term). As I understand they situation here, such software is either in a gray area legally, or the author has made some kind of special agreement with the RAR people. > While I agree with the general refusal of .rar or other non-free > archive formats, a useful archiving tool should still be able to > extract them. Creating them is an other issue. > > There is a free (open source) un-rar for Linux which AFAIK can at > least handle .rar archives below v3. That's part of my point -- unrar-free is the only decoder free enough to be distributed by Debian, and yes, it's limited to decoding old versions or the rar file format. Wikipedia seems to say it was based on RAR as it looked before some license terms change. /Jorgen -- // Jorgen Grahn O o . From steve+comp.lang.python at pearwood.info Fri Feb 18 19:03:06 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Feb 2011 00:03:06 GMT Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> Message-ID: <4d5f08b9$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Feb 2011 04:43:13 -0800, Xah Lee wrote: > for example, when you type >= in python, the text editor can > automatically change it to ? (when it detects that it's appropriate, > e.g. there's a ?if? nearby) You can't rely on the presence of an `if`. flag = x >= y value = lookup[x >= y] filter(lambda x, y: x >= y, sequence) Not that you need to. There are no circumstances in Python where the meaning of >= is changed by an `if` statement. Followups set to comp.lang.python. -- Steven From grahn+nntp at snipabacken.se Fri Feb 18 19:07:28 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 19 Feb 2011 00:07:28 GMT Subject: How to use Python well? References: Message-ID: On Thu, 2011-02-17, Roy Smith wrote: > In article , > Jorgen Grahn wrote: > >> - Write user documentation and build/installation scripts. Since I'm >> on Unix, that means man pages and a Makefile. > > Wow, I haven't built a man page in eons. These days, user documentation > for me means good help text for argparse to use. Perhaps I'm old-fashioned, but all other software I use (on Unix) has man pages. I /expect/ there to be one. (It's not hard to write a man page either, if you have a decent one as a template.) Help texts are better than nothing though (and unlike man pages they work on Windows too). > If I need something > more than that, I'll write it up in our wiki. I guess you're working within an organization? Local rules override personal preferences -- if everyone else is using the wiki, I guess you must do too. I have to say though that *not* handling the documentation together with the source code is harmful. If source code and documentation aren't in version control together, they *will* go out of sync. >> Anyway, I don't feel bad if I don't find any classes at first. > > Same here. I don't usually find a reason to refactor things into > classes until I've written the second or third line of code :-) > > Somewhat more seriously, the big clue for me that I've got a class > hiding in there is when I start having all sorts of globals. That's > usually a sign you've done something wrong. Or a whole bunch of related arguments to a function, and/or the same arguments being passed to many functions. /Jorgen -- // Jorgen Grahn O o . From roy at panix.com Fri Feb 18 19:20:58 2011 From: roy at panix.com (Roy Smith) Date: Fri, 18 Feb 2011 19:20:58 -0500 Subject: How to use Python well? References: Message-ID: In article , Jorgen Grahn wrote: > On Thu, 2011-02-17, Roy Smith wrote: > > In article , > > Jorgen Grahn wrote: > > > >> - Write user documentation and build/installation scripts. Since I'm > >> on Unix, that means man pages and a Makefile. > > > > Wow, I haven't built a man page in eons. These days, user documentation > > for me means good help text for argparse to use. > > Perhaps I'm old-fashioned, but all other software I use (on Unix) has > man pages. I /expect/ there to be one. (It's not hard to write a man > page either, if you have a decent one as a template.) The nice thing about help text is that it keeps the documentation and the code in one place, which makes it a little more likely people will actually update the docs as they update the code. > I guess you're working within an organization? FSVO "organization", but yes. > Local rules override personal preferences -- if everyone else is > using the wiki, I guess you must do too. I've become very enamored of wikis because of the lost activation energy barrier and instant feedback. To update a man page (info node, etc), you need to find the source document, perhaps check it out, edit it, submit it back to version control, install the new version in /usr/man, and so on. People tend not to bother. Wikis are so much more lightweight, they're that much more likely to get kept current. > I have to say though that *not* handling the documentation together > with the source code is harmful. If source code and documentation > aren't in version control together, they *will* go out of sync. That is a valid argument against wikis. From ben+python at benfinney.id.au Fri Feb 18 19:39:17 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 19 Feb 2011 11:39:17 +1100 Subject: How to use Python well? References: Message-ID: <87d3moc0y2.fsf@benfinney.id.au> Roy Smith writes: > In article , > Jorgen Grahn wrote: > > > On Thu, 2011-02-17, Roy Smith wrote: > > > These days, user documentation for me means good help text for > > > argparse to use. > > > > Perhaps I'm old-fashioned, but all other software I use (on Unix) > > has man pages. I /expect/ there to be one. (It's not hard to write a > > man page either, if you have a decent one as a template.) > > The nice thing about help text is that it keeps the documentation and > the code in one place, which makes it a little more likely people will > actually update the docs as they update the code. Yes, that's nice for the programmer. But isn't the point of the man page to be nice for the users? The man pages document many more things than help text output from the program. -- \ ?Very few things happen at the right time, and the rest do not | `\ happen at all. The conscientious historian will correct these | _o__) defects.? ?Mark Twain, _A Horse's Tale_ | Ben Finney From steve+comp.lang.python at pearwood.info Fri Feb 18 20:01:57 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Feb 2011 01:01:57 GMT Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> Message-ID: <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Feb 2011 11:16:30 -0800, Westley Mart?nez wrote: > Allowing non-ascii characters as operators is a silly idea simply > because if xorg breaks, which it's very likely to do with the current > video drivers, I'm screwed. And if your hard drive crashes, you're screwed too. Why stop at "xorg breaks"? Besides, Windows and MacOS users will be scratching their head asking "xorg? Why should I care about xorg?" Programming languages are perfectly allowed to rely on the presence of a working environment. I don't think general purpose programming languages should be designed with reliability in the presence of a broken environment in mind. Given the use-cases people put Python to, it is important for the language to *run* without a GUI environment. It's also important (but less so) to allow people to read and/or write source code without a GUI, which means continuing to support the pure-ASCII syntax that Python already supports. But Python already supports non-ASCII source files, with an optional encoding line in the first two lines of the file, so it is already possible to write Python code that runs without X but can't be easily edited without a modern, Unicode-aware editor. > Not only does the Linux virtual terminal not > support displaying these special characters, but there's also no way of > inputting them. That's a limitation of the Linux virtual terminal. In 1984 I used to use a Macintosh which was perfectly capable of displaying and inputting non- ASCII characters with a couple of key presses. Now that we're nearly a quarter of the way into 2011, I'm using a Linux PC that makes entering a degree sign or a pound sign a major undertaking, if it's even possible at all. It's well past time for Linux to catch up with the 1980s. > On top of that, these special characters require more > bytes to display than ascii text, which would bloat source files > unnecessarily. Oh come on now, now you're just being silly. "Bloat source files"? From a handful of double-byte characters? Cry me a river! This is truly a trivial worry: >>> s = "if x >= y:\n" >>> u = u"if x ? y:\n" >>> len(s) 11 >>> len(u.encode('utf-8')) 12 The source code to the decimal module in Python 3.1 is 205470 bytes in size. It contains 63 instances of ">=" and 62 of "<=". Let's suppose every one of those were changed to ? or ? characters. This would "bloat" the file by 0.06%. Oh the humanity!!! How will my 2TB hard drive cope?!?! > You say we have symbol congestion, but in reality we have our own symbol > bloat. Japanese has more or less than three punctuation marks, while > English has perhaps more than the alphabet! The fundamental point here > is using non-ascii operators violates the Zen of Python. It violates > "Simple is better than complex," as well as "There should be one-- and > preferably only one --obvious way to do it." Define "simple" and "complex" in this context. It seems to me that single character symbols such as ? are simpler than digraphs such as >=, simply because the parser knows what the symbol is after reading a single character. It doesn't have to read on to tell whether you meant > or >=. You can add complexity to one part of the language (hash tables are more complex than arrays) in order to simplify another part (dict lookup is simpler and faster than managing your own data structure in a list). And as for one obvious way, there's nothing obvious about using a | b for set union. Why not a + b? The mathematician in me wants to spell set union and intersection as a ? b ? c, which is the obvious way to me (even if my lousy editor makes it a PITA to *enter* the symbols). The lack of good symbols for operators in ASCII is a real problem. Other languages have solved it in various ways, sometimes by using digraphs (or higher-order symbols), and sometimes by using Unicode (or some platform/ language specific equivalent). I think that given the poor support for Unicode in the general tools we use, the use of non-ASCII symbols will have to wait until Python4. Hopefully by 2020 input methods will have improved, and maybe even xorg be replaced by something less sucky. I think that the push for better and more operators will have to come from the Numpy community. Further reading: http://mail.python.org/pipermail/python-dev/2008-November/083493.html -- Steven From spamhead42 at gmail.com Fri Feb 18 20:19:18 2011 From: spamhead42 at gmail.com (spam head) Date: Fri, 18 Feb 2011 17:19:18 -0800 (PST) Subject: Making Line Graphs Message-ID: I'm looking for an easy way to display simple line graphs generated by a python program in Windows. It could be done from within the program, or I could write the information out to a file and call an external program. Either is fine. Does anybody have any recommendations for a good program from generating these simple graphs? From no.email at nospam.invalid Fri Feb 18 20:23:34 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 18 Feb 2011 17:23:34 -0800 Subject: Making Line Graphs References: Message-ID: <7x62sg24x5.fsf@ruckus.brouhaha.com> spam head writes: > I'm looking for an easy way to display simple line graphs generated by > a python program in Windows. It could be done from within the > program, or I could write the information out to a file and call an > external program. Either is fine. I've used gnuplot and rrdtool for this in recent projects. Rrdtool is for ongoing time series and gnuplot is for more general graphing. I looked at Timeplot too, which looks really neat, but I didn't try to use it. From anikom15 at gmail.com Fri Feb 18 21:14:32 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 18 Feb 2011 18:14:32 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1298081672.6692.24.camel@localhost.localdomain> On Sat, 2011-02-19 at 01:01 +0000, Steven D'Aprano wrote: > On Fri, 18 Feb 2011 11:16:30 -0800, Westley Mart?nez wrote: > > > Allowing non-ascii characters as operators is a silly idea simply > > because if xorg breaks, which it's very likely to do with the current > > video drivers, I'm screwed. > > And if your hard drive crashes, you're screwed too. Why stop at "xorg > breaks"? Because I can still edit text files in the terminal. I guess you could manually control the magnet in the hard-drive if it failed but that'd be horrifically tedious. > Besides, Windows and MacOS users will be scratching their head asking > "xorg? Why should I care about xorg?" Why should I care if my programs run on Windows and Mac? Because I'm a nice guy I guess.... > Programming languages are perfectly allowed to rely on the presence of a > working environment. I don't think general purpose programming languages > should be designed with reliability in the presence of a broken > environment in mind. > > Given the use-cases people put Python to, it is important for the > language to *run* without a GUI environment. It's also important (but > less so) to allow people to read and/or write source code without a GUI, > which means continuing to support the pure-ASCII syntax that Python > already supports. But Python already supports non-ASCII source files, > with an optional encoding line in the first two lines of the file, so it > is already possible to write Python code that runs without X but can't be > easily edited without a modern, Unicode-aware editor. > > > Not only does the Linux virtual terminal not > > support displaying these special characters, but there's also no way of > > inputting them. > > That's a limitation of the Linux virtual terminal. In 1984 I used to use > a Macintosh which was perfectly capable of displaying and inputting non- > ASCII characters with a couple of key presses. Now that we're nearly a > quarter of the way into 2011, I'm using a Linux PC that makes entering a > degree sign or a pound sign a major undertaking, if it's even possible at > all. It's well past time for Linux to catch up with the 1980s. I feel it's unnecessary for Linux to "catch up" simply because we have no need for these special characters! When I read Python code, I only see text from Latin-1, which is easy to input and every *decent* font supports it. When I read C code, I only see text from Latin-1. When I read code from just about everything else that's plain text, I only see text from Latin-1. Even Latex, which is designed for typesetting mathematical formulas, only allows ASCII in its input. Languages that accept non-ASCII input have always been somewhat esoteric. There's nothing wrong with being different, but there is something wrong in being so different that your causing problems or at least speed bumps for particular users. > > On top of that, these special characters require more > > bytes to display than ascii text, which would bloat source files > > unnecessarily. > > Oh come on now, now you're just being silly. "Bloat source files"? From a > handful of double-byte characters? Cry me a river! > > This is truly a trivial worry: > > >>> s = "if x >= y:\n" > >>> u = u"if x ? y:\n" > >>> len(s) > 11 > >>> len(u.encode('utf-8')) > 12 > > > The source code to the decimal module in Python 3.1 is 205470 bytes in > size. It contains 63 instances of ">=" and 62 of "<=". Let's suppose > every one of those were changed to ? or ? characters. This would "bloat" > the file by 0.06%. > > Oh the humanity!!! How will my 2TB hard drive cope?!?! A byte saved is a byte earned. What about embedded systems trying to conserve as much resources as possible? > > You say we have symbol congestion, but in reality we have our own symbol > > bloat. Japanese has more or less than three punctuation marks, while > > English has perhaps more than the alphabet! The fundamental point here > > is using non-ascii operators violates the Zen of Python. It violates > > "Simple is better than complex," as well as "There should be one-- and > > preferably only one --obvious way to do it." > > Define "simple" and "complex" in this context. > > It seems to me that single character symbols such as ? are simpler than > digraphs such as >=, simply because the parser knows what the symbol is > after reading a single character. It doesn't have to read on to tell > whether you meant > or >=. > > You can add complexity to one part of the language (hash tables are more > complex than arrays) in order to simplify another part (dict lookup is > simpler and faster than managing your own data structure in a list). I believe dealing with ASCII is simpler than dealing with Unicode, for reasons on both the developer's and user's side. > And as for one obvious way, there's nothing obvious about using a | b for > set union. Why not a + b? The mathematician in me wants to spell set > union and intersection as a ? b ? c, which is the obvious way to me (even > if my lousy editor makes it a PITA to *enter* the symbols). Not all programmers are mathematicians (in fact I'd say most aren't). I know what those symbols mean, but some people might think "a u b n c ... what?" | actually makes sense because it relates to bitwise OR in which bits are turned on. Here's an example just for context: 01010101 | 10101010 = 11111111 {1, 2, 3} | {4, 5, 6} = {1, 2, 3, 4, 5, 6} For me, someone who is deeply familiar with bitwise operations but not very familiar with sets, I found the set syntax to be quite easy to understand. > The lack of good symbols for operators in ASCII is a real problem. Other > languages have solved it in various ways, sometimes by using digraphs (or > higher-order symbols), and sometimes by using Unicode (or some platform/ > language specific equivalent). I think that given the poor support for > Unicode in the general tools we use, the use of non-ASCII symbols will > have to wait until Python4. Hopefully by 2020 input methods will have > improved, and maybe even xorg be replaced by something less sucky. > > I think that the push for better and more operators will have to come > from the Numpy community. Further reading: > > > http://mail.python.org/pipermail/python-dev/2008-November/083493.html > > > -- > Steven > You have provided me with some well thought out arguments and have stimulated my young programmer's mind, but I think we're coming from different angles. You seem to come from a more math-minded, idealist angle, while I come from a more practical angle. Being a person who has had to deal with the ? in my last name and Japanese text on a variety of platforms, I've found the current methods of non-ascii input to be largely platform-dependent and---for lack of a better word---crappy, i.e. not suitable for a 'wide-audience' language like Python. From anikom15 at gmail.com Fri Feb 18 21:20:57 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 18 Feb 2011 18:20:57 -0800 Subject: How to use Python well? In-Reply-To: <87d3moc0y2.fsf@benfinney.id.au> References: <87d3moc0y2.fsf@benfinney.id.au> Message-ID: <1298082057.6692.26.camel@localhost.localdomain> On Sat, 2011-02-19 at 11:39 +1100, Ben Finney wrote: > Roy Smith writes: > > > In article , > > Jorgen Grahn wrote: > > > > > On Thu, 2011-02-17, Roy Smith wrote: > > > > These days, user documentation for me means good help text for > > > > argparse to use. > > > > > > Perhaps I'm old-fashioned, but all other software I use (on Unix) > > > has man pages. I /expect/ there to be one. (It's not hard to write a > > > man page either, if you have a decent one as a template.) > > > > The nice thing about help text is that it keeps the documentation and > > the code in one place, which makes it a little more likely people will > > actually update the docs as they update the code. > > Yes, that's nice for the programmer. But isn't the point of the man page > to be nice for the users? The man pages document many more things than > help text output from the program. > > -- > \ ?Very few things happen at the right time, and the rest do not | > `\ happen at all. The conscientious historian will correct these | > _o__) defects.? ?Mark Twain, _A Horse's Tale_ | > Ben Finney >From what I've seen, the man pages are supposed to be in depth information that covers every nook and cranny of every option while the --help option is supposed to simply print a summary in case one forgets the syntax, but nowadays they've kind of been blended together. From no.email at nospam.invalid Fri Feb 18 21:24:43 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 18 Feb 2011 18:24:43 -0800 Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xei74zrpw.fsf@ruckus.brouhaha.com> Westley Mart?nez writes: > When I read Python code, I only > see text from Latin-1, which is easy to input and every *decent* font > supports it. When I read C code, I only see text from Latin-1. When I > read code from just about everything else that's plain text, I only see > text from Latin-1. Even Latex, which is designed for typesetting > mathematical formulas, only allows ASCII in its input. Languages that > accept non-ASCII input have always been somewhat esoteric. Maybe we'll see more of them as time goes by. C, Python, and Latex all predate Unicode by a number of years. If Latex were written today it would probably accept Unicode for math symbols, accented and non-Latin characters, etc. From ben+python at benfinney.id.au Fri Feb 18 22:01:08 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 19 Feb 2011 14:01:08 +1100 Subject: How to use Python well? References: <87d3moc0y2.fsf@benfinney.id.au> Message-ID: <878vxcbudn.fsf@benfinney.id.au> Westley Mart?nez writes: > From what I've seen, the man pages are supposed to be in depth > information that covers every nook and cranny of every option Those are man pages the document commands. There are many more man pages on a typical Unix-like system, which do not document commands. This collection of a great deal of documentation for the operating system into a single ?manual? is one reason why users like man pages so much: we want to find anything installed on the system documented in that one place. -- \ ?The trouble with eating Italian food is that five or six days | `\ later you're hungry again.? ?George Miller | _o__) | Ben Finney From roy at panix.com Fri Feb 18 22:28:08 2011 From: roy at panix.com (Roy Smith) Date: Fri, 18 Feb 2011 22:28:08 -0500 Subject: How to use Python well? References: <87d3moc0y2.fsf@benfinney.id.au> <878vxcbudn.fsf@benfinney.id.au> Message-ID: In article <878vxcbudn.fsf at benfinney.id.au>, Ben Finney wrote: > This collection of a great deal of documentation for the operating > system into a single ???manual??? is one reason why users like man pages so > much: we want to find anything installed on the system documented in > that one place. What made man pages such a great technology back in the 70's was exactly what Ben is saying. Everything was on-line and instantly available for quick reference. Not to mention that you could use man as just another cog in the unix toolset and do things like grep all of /usr/man for a term (or an error message which appeared and you didn't know what had produced it). These were astonishing advances in usability vs. having printed manuals (which may or may not have been available to you). But, today we have such better tools available. HTML, for example. Whether it's a wiki or the generated output of sphinx/doxygen/etc, HTML provides for a much richer presentation. Which is more convenient: having the signal(3) man page reference "sigaction(2)" textually, or having it be a clickable link that can take me right there? HTML also gives you much greater formatting flexibility than what's still basically 35-year old nroff. If, for whatever reason, you're still wed to plain text, even info gives you much better capabilities than man. At least you get basic stuff like menus, document hierarchy, cross-linking, and browsing history. I'm not saying that help text is the be-all and end-all for documentation. I'm just saying that if you're going to do more than help text, it's hard to imagine putting any effort into producing man pages. Except possibly as the automated output of some multi-target documentation system which produces them as a by-product of producing other, richer, formats. From ben+python at benfinney.id.au Fri Feb 18 22:37:37 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 19 Feb 2011 14:37:37 +1100 Subject: How to use Python well? References: <87d3moc0y2.fsf@benfinney.id.au> <878vxcbudn.fsf@benfinney.id.au> Message-ID: <874o80bsou.fsf@benfinney.id.au> Roy Smith writes: > Whether it's a wiki or the generated output of sphinx/doxygen/etc, HTML > provides for a much richer presentation. Which is more convenient: > having the signal(3) man page reference "sigaction(2)" textually, or > having it be a clickable link that can take me right there? My man page browser does exactly that: the reference to another man page is clickable, bringing me directly to the approrpiate page. If yours doesn't, perhaps that's what needs to be addressed? > HTML also gives you much greater formatting flexibility than what's > still basically 35-year old nroff. Full agreement there. > If, for whatever reason, you're still wed to plain text, even info > gives you much better capabilities than man. Yet the manual system is reliably installed on any Unix system I'm likely to encounter. The ?info? system is not. Which is my point: there's one place the documentation is expected to be. > I'm not saying that help text is the be-all and end-all for > documentation. Nor am I making any similar claim for the Unix manual system. But it is the common baseline which can be relied upon ? unless vendors fail to provide it. Hence the appeal not to do that. -- \ ?Every man would like to be God, if it were possible; some few | `\ find it difficult to admit the impossibility.? ?Bertrand | _o__) Russell, _Power: A New Social Analysis_, 1938 | Ben Finney From googler.1.webmaster at spamgourmet.com Fri Feb 18 23:10:43 2011 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 18 Feb 2011 20:10:43 -0800 (PST) Subject: Python leaks in cyclic garbage collection Message-ID: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> Hi, I have some problems with Python and the garbage collection. In the following piece of code I create a simple gargabe collection but I am still wondering why the finalizers are never called - at least on exit of Py they should be called somehow. What do I miss here? I know, there is no deterministic way how to resolve this though. class Foo(): def __init__(self): self.b=Bar(self) def __del__(self): print "Free Foo" class Bar(): def __init__(self, f): self.f=f def __del__(self): print "Free Bar" f=Foo() print f From googler.1.webmaster at spamgourmet.com Fri Feb 18 23:13:29 2011 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 18 Feb 2011 20:13:29 -0800 (PST) Subject: Python leaks in cyclic garbage collection References: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> Message-ID: <575aff5b-e8fc-4d20-832e-60810a217aa8@z31g2000vbs.googlegroups.com> Thanks a lot for any help!!! Bye, moerchendiser2k3 From hayesjdno3 at yahoo.com Fri Feb 18 23:29:13 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Fri, 18 Feb 2011 20:29:13 -0800 (PST) Subject: file/folder naming Message-ID: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> im trying to use wxpython to get a source file/files, then a destination folder to write them to. the file and folder picker works. the problem is, actually copying (actually shutil.copy2() ). i get an except error, as if the destination file name is not correct. looking at the print lines the destination looks right. i used os.path.join to join the folder path and the filebasename. i can hear it now, that this belongs on the wxpython page, and i will be posting there as well. but, im fairly certain its something in this "for files in sourcepath:" import wx,os,string,shutil,getpass from datetime import * def backupfiles(): dialog = wx.FileDialog(None, "Choose a source file :", style=1 | wx.MULTIPLE ) if dialog.ShowModal() == wx.ID_OK: sourcepath = dialog.GetPaths() else: dialog.Destroy() dialog = wx.DirDialog(None, "Choose a destination directory :", style=1 ) if dialog.ShowModal() == wx.ID_OK: destpath = dialog.GetPath() else: dialog.Destroy() print "sourcepath is :",sourcepath print "destpath is :",destpath for files in sourcepath: print "destpath is :",os.path.join(destpath,os.path.basename(files)) try: shutil.copy2(sourcepath, os.path.join(destpath,os.path.basename(files))) except: print "error file" class MyForm(wx.Frame): """make a frame, inherits wx.Frame""" def __init__(self): # create a frame, no parent, default to wxID_ANY wx.Frame.__init__(self, None, wx.ID_ANY, title="FacBac", pos=(300, 150), size=(500, 200)) self.SetBackgroundColour("purple") panel = wx.Panel(self, wx.ID_ANY) self.title1 = wx.StaticText(panel, wx.ID_ANY, "Backup") self.title2 = wx.StaticText(panel, wx.ID_ANY, "Restore") self.button1 = wx.Button(panel, id=-1, label='Backup ALL') self.button1.Bind(wx.EVT_BUTTON, self.button1Click) self.button1.SetToolTip(wx.ToolTip("this will backup your whole folder")) gridSizer = wx.GridSizer(rows=4, cols=2, hgap=5, vgap=5) gridSizer.Add(self.title1, 0, wx.ALL|wx.ALIGN_CENTER, 5) gridSizer.Add(self.title2, 0, wx.ALL|wx.ALIGN_CENTER, 5) gridSizer.Add(self.button1, 0, wx.ALL|wx.EXPAND, 5) topSizer = wx.BoxSizer(wx.VERTICAL) topSizer.Add(gridSizer, 0, wx.ALL|wx.EXPAND, 5) self.SetSizeHints(500,200,500,200) panel.SetSizer(topSizer) topSizer.Fit(self) def button1Click(self, event): self.button1.SetLabel("Doing Backup") backupfiles() self.button1.SetLabel("Backup All") if __name__ == "__main__": app = wx.PySimpleApp() frame = MyForm().Show() #import wx.lib.inspection #wx.lib.inspection.InspectionTool().Show() app.MainLoop() From waldemar.osuch at gmail.com Fri Feb 18 23:34:09 2011 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Fri, 18 Feb 2011 20:34:09 -0800 (PST) Subject: Making Line Graphs In-Reply-To: Message-ID: <69721331-44bc-438d-8de2-267e1bd85075@glegroupsg2000goo.googlegroups.com> Standard answer in such a case is matplotlib http://matplotlib.sourceforge.net/ From clp2 at rebertia.com Fri Feb 18 23:49:09 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 18 Feb 2011 20:49:09 -0800 Subject: Python leaks in cyclic garbage collection In-Reply-To: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> References: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> Message-ID: On Fri, Feb 18, 2011 at 8:10 PM, moerchendiser2k3 wrote: > Hi, I have some problems with Python and the garbage collection. In > the following piece of code I create a simple gargabe collection but I > am still wondering why the finalizers are never called - at least on > exit of Py they should be called somehow. What do I miss here? Read The Fine Manual (all emphases added): http://docs.python.org/reference/datamodel.html#object.__del__ : "***It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits.***" "Note: [...] x.__del__() ? [...] is only called when x?s reference count reaches zero. Some common situations that may prevent the reference count of an object from going to zero include: circular references between objects [...] Circular references which are garbage are detected when the option cycle detector is enabled (it?s on by default), ***but can only be cleaned up if there are no Python-level __del__() methods involved***. Refer to the documentation for the `gc` module for more information about how __del__() methods are handled by the cycle detector, particularly the description of the `garbage` value." And following the pointer to gc.garbage's docs: http://docs.python.org/library/gc.html#gc.garbage : "Objects that have __del__() methods and are part of a reference cycle ***cause the entire reference cycle to be uncollectable*** [...] Python doesn?t collect such cycles automatically because, in general, it isn?t possible for Python to guess a safe order in which to run the __del__() methods. [...] It?s generally better to avoid the issue by not creating cycles containing objects with __del__() methods" Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Fri Feb 18 23:59:13 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 18 Feb 2011 20:59:13 -0800 Subject: file/folder naming In-Reply-To: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> References: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> Message-ID: On Fri, Feb 18, 2011 at 8:29 PM, ecu_jon wrote: > im trying to use wxpython to get a source file/files, then a > destination folder to write them to. the file and folder picker works. > the problem is, actually copying (actually shutil.copy2() ). i get an > except error Please include the exact text of the error message and accompanying Traceback. And always do so in the future. Cheers, Chris From aspineux at gmail.com Sat Feb 19 00:22:27 2011 From: aspineux at gmail.com (aspineux) Date: Fri, 18 Feb 2011 21:22:27 -0800 (PST) Subject: email library, get_payload() bug? References: Message-ID: On 18 f?v, 14:41, peterob wrote: > Helllo, > > I want to get the raw format of email body. the code Im using is > > ? ? ? ? for part in email.walk(): > ? ? ? ? ? ? ? ? if part.get_content_maintype() == 'multipart': > ? ? ? ? ? ? ? ? ? ? ? ? continue > ? ? ? ? ? ? ? ? if part.get_content_type() == 'text/plain': > # ? ? ? ? ? ? ? ? ? ? ? print part.get_content_type() > ? ? ? ? ? ? ? ? ? ? ? ? print part.get_payload(None,True) > > The problem is, that code adds one more '\n' at the and of the output > printed by get_payload(). Is that bug? > > Thanks. > > Best, > Peter No sure to undeerstand, but print add one '\n' by itself maybe using print part.get_payload(None,True), with a "," at the end to tell print not to add a "\n" hope this help From steve+comp.lang.python at pearwood.info Sat Feb 19 00:37:51 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Feb 2011 05:37:51 GMT Subject: file/folder naming References: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> Message-ID: <4d5f572f$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Feb 2011 20:29:13 -0800, ecu_jon wrote: > im trying to use wxpython to get a source file/files, then a destination > folder to write them to. the file and folder picker works. the problem > is, actually copying (actually shutil.copy2() ). i get an except error, > as if the destination file name is not correct. looking at the print > lines the destination looks right. i used os.path.join to join the > folder path and the filebasename. i can hear it now, that this belongs > on the wxpython page, and i will be posting there as well. but, im > fairly certain its something in this "for files in sourcepath:" > try: > shutil.copy2(sourcepath, > os.path.join(destpath,os.path.basename(files))) > except: > print "error file" There's your problem there: by hiding the *actual* error message Python provides, and substituting a rubbish, useless, generic "error file" message, you make it impossible to see what causes the error. Don't do that. Until you fix that, you can't diagnose errors, because the information needed to diagnose them is tossed away. -- Steven From steve+comp.lang.python at pearwood.info Sat Feb 19 00:40:41 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Feb 2011 05:40:41 GMT Subject: Python leaks in cyclic garbage collection References: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> Message-ID: <4d5f57d9$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Feb 2011 20:49:09 -0800, Chris Rebert wrote: > And following the pointer to gc.garbage's docs: > http://docs.python.org/library/gc.html#gc.garbage : "Objects that have > __del__() methods and are part of a reference cycle ***cause the entire > reference cycle to be uncollectable*** [...] Python doesn?t collect such > cycles automatically because, in general, it isn?t possible for Python > to guess a safe order in which to run the __del__() methods. [...] It?s > generally better to avoid the issue by not creating cycles containing > objects with __del__() methods" Another solution is to manually break the cycle, perhaps by providing a "close" method, and requiring the caller to use it. -- Steven From hayesjdno3 at yahoo.com Sat Feb 19 01:10:08 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Fri, 18 Feb 2011 22:10:08 -0800 (PST) Subject: file/folder naming References: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> Message-ID: <1481c3a7-6e11-44b3-9a85-e3890fcf4c6a@n11g2000vbm.googlegroups.com> On Feb 18, 11:59?pm, Chris Rebert wrote: > On Fri, Feb 18, 2011 at 8:29 PM, ecu_jon wrote: > > im trying to use wxpython to get a source file/files, then a > > destination folder to write them to. the file and folder picker works. > > the problem is, actually copying (actually shutil.copy2() ). i get an > > except error > > Please include the exact text of the error message and accompanying > Traceback. And always do so in the future. > > Cheers, > Chris as i was using tr/except, there is no traceback, or i would have done so. the except error comes back and says it cant copy to the folder. From hayesjdno3 at yahoo.com Sat Feb 19 01:13:42 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Fri, 18 Feb 2011 22:13:42 -0800 (PST) Subject: file/folder naming References: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> <4d5f572f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: ok changed the try/except to just a file copy and got this: sourcepath is : [u'I:\\college\\spring11\\capstone-project\ \facbac-009.py'] destpath is : V:\week3 destpath is : V:\week3\facbac-009.py Traceback (most recent call last): File "I:\college\spring11\capstone-project\folder.py", line 53, in button1Click backupfiles() File "I:\college\spring11\capstone-project\folder.py", line 19, in backupfiles shutil.copy2(sourcepath, os.path.join(destpath,os.path.basename(files))) File "C:\Python27\lib\shutil.py", line 127, in copy2 copyfile(src, dst) File "C:\Python27\lib\shutil.py", line 67, in copyfile if _samefile(src, dst): File "C:\Python27\lib\shutil.py", line 62, in _samefile return (os.path.normcase(os.path.abspath(src)) == File "C:\Python27\lib\ntpath.py", line 471, in abspath path = _getfullpathname(path) TypeError: coercing to Unicode: need string or buffer, list found yes i see the list. but shouldnt this "for files in sourcepath:" parse thru the list ... ? From yanghatespam at gmail.com Sat Feb 19 01:15:01 2011 From: yanghatespam at gmail.com (Yang Zhang) Date: Fri, 18 Feb 2011 22:15:01 -0800 Subject: Python subprocesses experience mysterious delay in receiving stdin EOF In-Reply-To: References: <4D52037E.4000809@mrabarnett.plus.com> <4D52C0C7.4040004@sequans.com> Message-ID: After way too much time, I figured it out, after a quote from [this post](http://fixunix.com/questions/379652-sending-eof-named-pipe.html) jumped out at me: > See the "I/O on Pipes and FIFOs" section of pipe(7) ("man 7 pipe") > > "If all file descriptors referring to the write end of a pipe have > been closed, then an attempt to read(2) from the pipe will see > end-of-file (read(2) will return 0)." I should've known this, but it never occurred to me - had nothing to do with Python in particular. What was happening was: the subprocesses were getting forked with open (writer) file descriptors to each others' pipes. As long as there are open writer file descriptors to a pipe, readers won't see EOF. E.g.: p1=Popen(..., stdin=PIPE, ...) # creates a pipe the parent process can write to p2=Popen(...) # inherits the writer FD - as long as p2 exists, p1 won't see EOF Turns out there's a `close_fds` parameter to `Popen`, so the solution is to pass `close_fds=True`. All simple and obvious in hindsight, but still managed to cost at least a couple eyeballs good chunks of time. On Sun, Feb 13, 2011 at 11:52 PM, Yang Zhang wrote: > Anybody else see this issue? > > On Thu, Feb 10, 2011 at 10:37 AM, Yang Zhang wrote: >> On Thu, Feb 10, 2011 at 12:28 AM, Jean-Michel Pichavant >> wrote: >>> Yang Zhang wrote: >>>> >>>> On Wed, Feb 9, 2011 at 11:01 AM, MRAB wrote: >>>> >>>>> >>>>> On 09/02/2011 01:59, Yang Zhang wrote: >>>>> >>>>>> >>>>>> I reduced a problem I was seeing in my application down into the >>>>>> following test case. In this code, a parent process concurrently >>>>>> spawns 2 (you can spawn more) subprocesses that read a big message >>>>>> from the parent over stdin, sleep for 5 seconds, and write something >>>>>> back. However, there's unexpected waiting happening somewhere, causing >>>>>> the code to complete in 10 seconds instead of the expected 5. >>>>>> >>>>>> If you set `verbose=True`, you can see that the straggling subprocess >>>>>> is receiving most of the messages, then waiting for the last chunk of >>>>>> 3 chars---it's not detecting that the pipe has been closed. >>>>>> Furthermore, if I simply don't do anything with the second process >>>>>> (`doreturn=True`), the first process will *never* see the EOF. >>>>>> >>>>>> Any ideas what's happening? Further down is some example output. >>>>>> Thanks in advance. >>>>>> >>>>>> ? ?from subprocess import * >>>>>> ? ?from threading import * >>>>>> ? ?from time import * >>>>>> ? ?from traceback import * >>>>>> ? ?import sys >>>>>> ? ?verbose = False >>>>>> ? ?doreturn = False >>>>>> ? ?msg = (20*4096+3)*'a' >>>>>> ? ?def elapsed(): return '%7.3f' % (time() - start) >>>>>> ? ?if sys.argv[1:]: >>>>>> ? ? ?start = float(sys.argv[2]) >>>>>> ? ? ?if verbose: >>>>>> ? ? ? ?for chunk in iter(lambda: sys.stdin.read(4096), ''): >>>>>> ? ? ? ? ?print>> ?sys.stderr, '..', time(), sys.argv[1], 'read', >>>>>> len(chunk) >>>>>> ? ? ?else: >>>>>> ? ? ? ?sys.stdin.read() >>>>>> ? ? ?print>> ?sys.stderr, elapsed(), '..', sys.argv[1], 'done reading' >>>>>> ? ? ?sleep(5) >>>>>> ? ? ?print msg >>>>>> ? ?else: >>>>>> ? ? ?start = time() >>>>>> ? ? ?def go(i): >>>>>> ? ? ? ?print elapsed(), i, 'starting' >>>>>> ? ? ? ?p = Popen(['python','stuckproc.py',str(i), str(start)], >>>>>> stdin=PIPE, stdout=PIPE) >>>>>> ? ? ? ?if doreturn and i == 1: return >>>>>> ? ? ? ?print elapsed(), i, 'writing' >>>>>> ? ? ? ?p.stdin.write(msg) >>>>>> ? ? ? ?print elapsed(), i, 'closing' >>>>>> ? ? ? ?p.stdin.close() >>>>>> ? ? ? ?print elapsed(), i, 'reading' >>>>>> ? ? ? ?p.stdout.read() >>>>>> ? ? ? ?print elapsed(), i, 'done' >>>>>> ? ? ?ts = [Thread(target=go, args=(i,)) for i in xrange(2)] >>>>>> ? ? ?for t in ts: t.start() >>>>>> ? ? ?for t in ts: t.join() >>>>>> >>>>>> Example output: >>>>>> >>>>>> ? ? ?0.001 0 starting >>>>>> ? ? ?0.003 1 starting >>>>>> ? ? ?0.005 0 writing >>>>>> ? ? ?0.016 1 writing >>>>>> ? ? ?0.093 0 closing >>>>>> ? ? ?0.093 0 reading >>>>>> ? ? ?0.094 1 closing >>>>>> ? ? ?0.094 1 reading >>>>>> ? ? ?0.098 .. 1 done reading >>>>>> ? ? ?5.103 1 done >>>>>> ? ? ?5.108 .. 0 done reading >>>>>> ? ? 10.113 0 done >>>>>> >>>>>> >>>>> >>>>> I changed 'python' to the path of python.exe and 'stuckproc.py' to its >>>>> full path and tried it with Python 2.7 on Windows XP Pro. It worked as >>>>> expected. >>>>> >>>> >>>> Good point - I didn't specify that I'm seeing this on Linux (Ubuntu >>>> 10.04's Python 2.6). >>>> >>>> >>> >>> python test.py ? 0.000 0 starting >>> ?0.026 0 writing >>> ?0.026 0 closing >>> ?0.026 0 reading >>> ?0.029 .. 0 done reading >>> ?0.030 1 starting >>> ?0.038 1 writing >>> ?0.058 1 closing >>> ?0.058 1 reading >>> ?0.061 .. 1 done reading >>> ?5.026 0 done >>> ?5.061 1 done >>> >>> on debian lenny (Python 2.5) >>> >>> JM >>> >> >> FWIW, this is consistently reproduce-able across all the Ubuntu 10.04s >> I've tried. You may need to increase the message size so that it's >> large enough for your system. >> >> -- >> Yang Zhang >> http://yz.mit.edu/ >> > > > > -- > Yang Zhang > http://yz.mit.edu/ > -- Yang Zhang http://yz.mit.edu/ From 71david at libero.it Sat Feb 19 01:19:57 2011 From: 71david at libero.it (David) Date: Sat, 19 Feb 2011 07:19:57 +0100 Subject: Unit testing multiprocessing code on Windows References: Message-ID: <1nbovu9rtsx8d$.1oqt1uxu8qd82$.dlg@40tude.net> Il Thu, 17 Feb 2011 18:31:59 -0500, Matt Chaput ha scritto: > > The problem is that with both "python setup.py tests" and "nosetests", > Maybe multiprocessing is starting new Windows processes by copying the > command line of the current process? But if the command line is > "nosetests", it's a one way ticket to an infinite explosion of processes. You can adapt this code to inhibit test execution if another process is testing yet. http://code.activestate.com/recipes/474070-creating-a-single-instance-application/ From steve+comp.lang.python at pearwood.info Sat Feb 19 01:29:39 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Feb 2011 06:29:39 GMT Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d5f6352$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Feb 2011 18:14:32 -0800, Westley Mart?nez wrote: >> Besides, Windows and MacOS users will be scratching their head asking >> "xorg? Why should I care about xorg?" > Why should I care if my programs run on Windows and Mac? Because I'm a > nice guy I guess.... Python is a programming language that is operating system independent, and not just a Linux tool. So you might not care about your Python programs running on Windows, but believe me, the Python core developers care about Python running on Windows and Mac OS. (Even if sometimes their lack of resources make Windows and Mac somewhat second-class citizens.) >> That's a limitation of the Linux virtual terminal. In 1984 I used to >> use a Macintosh which was perfectly capable of displaying and inputting >> non- ASCII characters with a couple of key presses. Now that we're >> nearly a quarter of the way into 2011, I'm using a Linux PC that makes >> entering a degree sign or a pound sign a major undertaking, if it's >> even possible at all. It's well past time for Linux to catch up with >> the 1980s. > > I feel it's unnecessary for Linux to "catch up" simply because we have > no need for these special characters! Given that your name is Westley Mart?nez, that's an astonishing claim! How do you even write your name in your own source code??? Besides, speak for yourself, not for "we". I have need for them. > When I read Python code, I only > see text from Latin-1, which is easy to input Hmmm. I wish I knew an easy way to input it. All the solutions I've come across are rubbish. How do you enter (say) ? at the command line of a xterm? But in any case, ASCII != Latin-1, so you're already using more than ASCII characters. > Languages that > accept non-ASCII input have always been somewhat esoteric. Then I guess Python is esoteric, because with source code encodings it supports non-ASCII literals and even variables: [steve at sylar ~]$ cat encoded.py # -*- coding: utf-8 -*- r?sum? = "Some text here..." print(r?sum?) [steve at sylar ~]$ python3.1 encoded.py Some text here... [...] > A byte saved is a byte earned. What about embedded systems trying to > conserve as much resources as possible? Then they don't have to use multi-byte characters, just like they can leave out comments, and .pyo files, and use `ed` for their standard text editor instead of something bloated like vi or emacs. [...] > I believe dealing with ASCII is simpler than dealing with Unicode, for > reasons on both the developer's and user's side. Really? Well, I suppose if you want to define "you can't do this AT ALL" as "simpler", then, yes, ASCII is simpler. Using pure-ASCII means I am forced to write extra code because there aren't enough operators to be useful, e.g. element-wise addition versus concatenation. It means I'm forced to spell out symbols in full, like "British pound" instead of ?, and use legally dubious work-arounds like "(c)" instead of ?, and mispell words (including people's names) because I can't use the correct characters, and am forced to use unnecessarily long and clumsy English longhand for standard mathematical notation. If by simple you mean "I can't do what I want to do", then I agree completely that ASCII is simple. >> And as for one obvious way, there's nothing obvious about using a | b >> for set union. Why not a + b? The mathematician in me wants to spell >> set union and intersection as a ? b ? c, which is the obvious way to me >> (even if my lousy editor makes it a PITA to *enter* the symbols). > > Not all programmers are mathematicians (in fact I'd say most aren't). I > know what those symbols mean, but some people might think "a u b n c ... > what?" | actually makes sense because it relates to bitwise OR in which > bits are turned on. Not all programmers are C programmers who have learned that | represents bitwise OR. Some will say "a | b ... what?". I know I did, when I was first learning Python, and I *still* need to look them up to be sure I get them right. In other languages, | might be spelled as any of bitor() OR .OR. || ? [...] > Being a person who has > had to deal with the ? in my last name and Japanese text on a variety of > platforms, I've found the current methods of non-ascii input to be > largely platform-dependent and---for lack of a better word---crappy, Agreed one hundred percent! Until there are better input methods for non- ASCII characters, without the need for huge keyboards, Unicode is hard and ASCII easy, and Python can't *rely* on Unicode tokens. That doesn't mean that languages like Python can't support Unicode tokens, only that they shouldn't be the only way to do things. For a long time Pascal include (* *) as a synonym for { } because not all keyboards included the { } characters, and C has support for trigraphs: http://publications.gbdirect.co.uk/c_book/chapter2/alphabet_of_c.html Eventually, perhaps in another 20 years, digraphs like != and <= will go the same way as trigraphs. Just as people today find it hard to remember a time when keyboards didn't include { and }, hopefully they will find it equally hard to remember a time that you couldn't easily enter non-ASCII characters. -- Steven From clp2 at rebertia.com Sat Feb 19 01:36:08 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 18 Feb 2011 22:36:08 -0800 Subject: file/folder naming In-Reply-To: References: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> <4d5f572f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Feb 18, 2011 at 10:13 PM, ecu_jon wrote: > ok changed the try/except to just a file copy and got this: > sourcepath is : [u'I:\\college\\spring11\\capstone-project\ > \facbac-009.py'] > destpath is : V:\week3 > destpath is : V:\week3\facbac-009.py > Traceback (most recent call last): > ?File "I:\college\spring11\capstone-project\folder.py", line 53, in > button1Click > ? ?backupfiles() > ?File "I:\college\spring11\capstone-project\folder.py", line 19, in > backupfiles > ? ?shutil.copy2(sourcepath, > os.path.join(destpath,os.path.basename(files))) > ?File "C:\Python27\lib\shutil.py", line 127, in copy2 > ? ?copyfile(src, dst) > ?File "C:\Python27\lib\shutil.py", line 67, in copyfile > ? ?if _samefile(src, dst): > ?File "C:\Python27\lib\shutil.py", line 62, in _samefile > ? ?return (os.path.normcase(os.path.abspath(src)) == > ?File "C:\Python27\lib\ntpath.py", line 471, in abspath > ? ?path = _getfullpathname(path) > TypeError: coercing to Unicode: need string or buffer, list found > > yes i see the list. > but shouldnt this "for files in sourcepath:" parse thru the list ... ? That doesn't matter when your actual copy2() call still refers to `sourcepath` (the list): shutil.copy2(sourcepath, os.path.join(destpath,os.path.basename(files))) ^^^^^^^^^^ I presume you want `files` here rather than `sourcepath`. Incidentally, I think `sourcepath` is poorly named given that it's a list of paths, and `files` is also poorly named given that it's a single filepath. Cheers, Chris -- "There are only two hard problems in Computer Science: cache invalidation and naming things." ? Phil Karlton http://blog.rebertia.com From steve+comp.lang.python at pearwood.info Sat Feb 19 01:38:40 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Feb 2011 06:38:40 GMT Subject: file/folder naming References: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> <4d5f572f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d5f6570$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Feb 2011 22:13:42 -0800, ecu_jon wrote: > ok changed the try/except to just a file copy and got this: > sourcepath is : > [u'I:\\college\\spring11\\capstone-project\\facbac-009.py'] Note that it's a list. > shutil.copy2(sourcepath, > os.path.join(destpath,os.path.basename(files))) Note that you are calling copy2 with the first argument as a list. > TypeError: coercing to Unicode: need string or buffer, list found Note that the error tells you exactly what is wrong. > yes i see the list. > but shouldnt this "for files in sourcepath:" parse thru the list ... ? Yes it does. So what? You don't use files, you use sourcepath each time. >>> source = ['a', 'bb', 'ccc'] >>> for x in source: ... print(len(source)) ... 3 3 3 -- Steven From hayesjdno3 at yahoo.com Sat Feb 19 01:55:12 2011 From: hayesjdno3 at yahoo.com (ecu_jon) Date: Fri, 18 Feb 2011 22:55:12 -0800 (PST) Subject: file/folder naming References: <3a1203cc-2217-46c4-b843-854c90488634@b8g2000vbi.googlegroups.com> <4d5f572f$0$29972$c3e8da3$5496439d@news.astraweb.com> <4d5f6570$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <64e9df57-2639-40ec-a531-c0de98087ae2@y3g2000vbh.googlegroups.com> On Feb 19, 1:38?am, Steven D'Aprano wrote: > On Fri, 18 Feb 2011 22:13:42 -0800, ecu_jon wrote: > > ok changed the try/except to just a file copy and got this: > > sourcepath is : > > [u'I:\\college\\spring11\\capstone-project\\facbac-009.py'] > > Note that it's a list. > > > ? ? shutil.copy2(sourcepath, > > ? ? ? ? ? ? ? ? ?os.path.join(destpath,os.path.basename(files))) > > Note that you are calling copy2 with the first argument as a list. > > > TypeError: coercing to Unicode: need string or buffer, list found > > Note that the error tells you exactly what is wrong. > > > yes i see the list. > > but shouldnt this "for files in sourcepath:" parse thru the list ... ? > > Yes it does. So what? You don't use files, you use sourcepath each time. > > >>> source = ['a', 'bb', 'ccc'] > >>> for x in source: > > ... ? ? print(len(source)) > ... > 3 > 3 > 3 > > -- > Steven so i changed it to shutil.copy2(files, os.path.join(destpath,os.path.basename(files))) seems to be working. in the mornig when im not bleary eyed. ill check again but this look like the fix. thanks. From sathish at solitontech.com Sat Feb 19 01:59:54 2011 From: sathish at solitontech.com (Sathish S) Date: Sat, 19 Feb 2011 12:29:54 +0530 Subject: Python Path registry Key In-Reply-To: <1298056820.13025.17.camel@localhost.localdomain> References: <1298056820.13025.17.camel@localhost.localdomain> Message-ID: Hi, Thanks for replying. Yes sys.prefix works in the python shell window. But I have to find out python's path from another application running on windows. How can I access sys.prefix from that application. Thanks, Sathish On Sat, Feb 19, 2011 at 12:50 AM, Westley Mart?nez wrote: > On Fri, 2011-02-18 at 11:56 +0530, Sathish S wrote: > > Hi Ppl, > > > > > > I'm trying to launch IDLE from another application. For this I need > > the python directory path. I have been trying to get the Active Python > > versions path from the Windows registry. However, these registry > > entries seem not be consistent across various stations, that i > > checked. I'm reading the following resitry key to get the active > > versions path: Software\\Microsoft\\Windows\\CurrentVersion\\App Paths > > \\Python.exe. There are two entries in this key. Some stations have > > only one entry. Some do not have both. Probably they were removed > > while python was uninstall ed and was not added again when it was > > installed again. > > > > > > So what will be a good solution to get the Python path ? > > > > > > > > Thanks, > > Sathish > > > Try sys.prefix > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anikom15 at gmail.com Sat Feb 19 02:41:20 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 18 Feb 2011 23:41:20 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4d5f6352$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> <4d5f6352$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1298101280.10113.17.camel@localhost.localdomain> On Sat, 2011-02-19 at 06:29 +0000, Steven D'Aprano wrote: > On Fri, 18 Feb 2011 18:14:32 -0800, Westley Mart?nez wrote: > > >> Besides, Windows and MacOS users will be scratching their head asking > >> "xorg? Why should I care about xorg?" > > Why should I care if my programs run on Windows and Mac? Because I'm a > > nice guy I guess.... > > Python is a programming language that is operating system independent, > and not just a Linux tool. So you might not care about your Python > programs running on Windows, but believe me, the Python core developers > care about Python running on Windows and Mac OS. (Even if sometimes their > lack of resources make Windows and Mac somewhat second-class citizens.) You didn't seem to get my humor. It's ok; most people don't. > >> That's a limitation of the Linux virtual terminal. In 1984 I used to > >> use a Macintosh which was perfectly capable of displaying and inputting > >> non- ASCII characters with a couple of key presses. Now that we're > >> nearly a quarter of the way into 2011, I'm using a Linux PC that makes > >> entering a degree sign or a pound sign a major undertaking, if it's > >> even possible at all. It's well past time for Linux to catch up with > >> the 1980s. > > > > I feel it's unnecessary for Linux to "catch up" simply because we have > > no need for these special characters! > > Given that your name is Westley Mart?nez, that's an astonishing claim! > How do you even write your name in your own source code??? > > Besides, speak for yourself, not for "we". I have need for them. The ? is easy to input. (Vim has a diacritic feature) It's the funky mathematical symbols that are difficult. > > When I read Python code, I only > > see text from Latin-1, which is easy to input > > Hmmm. I wish I knew an easy way to input it. All the solutions I've come > across are rubbish. How do you enter (say) ? at the command line of a > xterm? I use this in my xorg.conf: Section "InputDevice" Identifier "Keyboard0" Driver "kbd" Option "XkbLayout" "us" Option "XkbVariant" "dvorak-alt-intl" EndSection Simply remove 'dvorak-' to get qwerty. It allows you to use the right Alt key as AltGr. For example: AltGr+' i = ? AltGr+c = ? AltGr+s = ? I don't work on Windows or Mac enough to have figured out how to do on those platforms, but I'm sure there's a simple way. Again, it's the funky symbols that would be difficult to input. > But in any case, ASCII != Latin-1, so you're already using more than > ASCII characters. > > > > Languages that > > accept non-ASCII input have always been somewhat esoteric. > > Then I guess Python is esoteric, because with source code encodings it > supports non-ASCII literals and even variables: > > [steve at sylar ~]$ cat encoded.py > # -*- coding: utf-8 -*- > r?sum? = "Some text here..." > print(r?sum?) > > [steve at sylar ~]$ python3.1 encoded.py > Some text here... I should reword that to "Languages that require non-ASCII input have always been somewhat esoteric" i.e. APL. > [...] > > A byte saved is a byte earned. What about embedded systems trying to > > conserve as much resources as possible? > > Then they don't have to use multi-byte characters, just like they can > leave out comments, and .pyo files, and use `ed` for their standard text > editor instead of something bloated like vi or emacs. Hey, I've heard of jobs where all you do is remove comments from source code, believe it or not! > [...] > > I believe dealing with ASCII is simpler than dealing with Unicode, for > > reasons on both the developer's and user's side. > > Really? Well, I suppose if you want to define "you can't do this AT ALL" > as "simpler", then, yes, ASCII is simpler. > > Using pure-ASCII means I am forced to write extra code because there > aren't enough operators to be useful, e.g. element-wise addition versus > concatenation. It means I'm forced to spell out symbols in full, like > "British pound" instead of ?, and use legally dubious work-arounds like > "(c)" instead of ?, and mispell words (including people's names) because > I can't use the correct characters, and am forced to use unnecessarily > long and clumsy English longhand for standard mathematical notation. > > If by simple you mean "I can't do what I want to do", then I agree > completely that ASCII is simple. I guess it's a matter of taste. I don't mind seeing my name as westley_martinez and am so use to seeing **, sqrt(), and / that seeing the original symbols is a bit foreign! > >> And as for one obvious way, there's nothing obvious about using a | b > >> for set union. Why not a + b? The mathematician in me wants to spell > >> set union and intersection as a ? b ? c, which is the obvious way to me > >> (even if my lousy editor makes it a PITA to *enter* the symbols). > > > > Not all programmers are mathematicians (in fact I'd say most aren't). I > > know what those symbols mean, but some people might think "a u b n c ... > > what?" | actually makes sense because it relates to bitwise OR in which > > bits are turned on. > > Not all programmers are C programmers who have learned that | represents > bitwise OR. Some will say "a | b ... what?". I know I did, when I was > first learning Python, and I *still* need to look them up to be sure I > get them right. > > In other languages, | might be spelled as any of > > bitor() OR .OR. || ? Good point, but C is a very popular language. I'm not saying we should follow C, but we should be aware that that's where the majority of Python's users are probably coming from (or from languages with C-like syntax) > [...] > > Being a person who has > > had to deal with the ? in my last name and Japanese text on a variety of > > platforms, I've found the current methods of non-ascii input to be > > largely platform-dependent and---for lack of a better word---crappy, > > Agreed one hundred percent! Until there are better input methods for non- > ASCII characters, without the need for huge keyboards, Unicode is hard > and ASCII easy, and Python can't *rely* on Unicode tokens. > > That doesn't mean that languages like Python can't support Unicode > tokens, only that they shouldn't be the only way to do things. For a long > time Pascal include (* *) as a synonym for { } because not all keyboards > included the { } characters, and C has support for trigraphs: > > http://publications.gbdirect.co.uk/c_book/chapter2/alphabet_of_c.html > > Eventually, perhaps in another 20 years, digraphs like != and <= will go > the same way as trigraphs. Just as people today find it hard to remember > a time when keyboards didn't include { and }, hopefully they will find it > equally hard to remember a time that you couldn't easily enter non-ASCII > characters. > > > -- > Steven That was good info. I think there is possibility for more symbols, but not for a long while, and I'll probably never use them if they do become available, because I don't really care. From andrea.crotti.0 at gmail.com Sat Feb 19 03:40:33 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sat, 19 Feb 2011 09:40:33 +0100 Subject: Python leaks in cyclic garbage collection In-Reply-To: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> References: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> Message-ID: <369CCB49-CE4F-4EFE-B831-1791C198DD69@gmail.com> Il giorno 19/feb/2011, alle ore 05.10, moerchendiser2k3 ha scritto: > Hi, I have some problems with Python and the garbage collection. In > the following piece of code I create a simple gargabe collection but I > am still wondering why the finalizers are never called - at least on > exit of Py they should be called somehow. What do I miss here? I know, > there is no deterministic way how to resolve this though. > > class Foo(): > > def __init__(self): > self.b=Bar(self) > > def __del__(self): > print "Free Foo" > > class Bar(): > def __init__(self, f): > self.f=f > > def __del__(self): > print "Free Bar" > > f=Foo() > print f > -- > http://mail.python.org/mailman/listinfo/python-list Wild guess: maybe when python exits they are called but sys.stdout has already been closed and nothing gets written on it anymore. From grahn+nntp at snipabacken.se Sat Feb 19 03:43:42 2011 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 19 Feb 2011 08:43:42 GMT Subject: How to use Python well? References: <87d3moc0y2.fsf@benfinney.id.au> <878vxcbudn.fsf@benfinney.id.au> <874o80bsou.fsf@benfinney.id.au> Message-ID: On Sat, 2011-02-19, Ben Finney wrote: > Roy Smith writes: ... >> HTML also gives you much greater formatting flexibility than what's >> still basically 35-year old nroff. > > Full agreement there. Some disagreement here. There are typographical features in nroff/troff today which you don't get in web browsers: ligatures and hyphenation for example. Then of course there's the argument that "formatting flexibility" isn't a good thing for reference manuals -- you want them to look similar no matter who wrote them. (Not that all man pages look similar in reality, but there are some pretty decent conventions which most follow). /Jorgen -- // Jorgen Grahn O o . From bugcy013 at gmail.com Sat Feb 19 04:44:08 2011 From: bugcy013 at gmail.com (Ganesh Kumar) Date: Sat, 19 Feb 2011 15:14:08 +0530 Subject: Python-os. Command Execution Message-ID: Hi, I am new to python programing. I have created one small application , application developed in python Tkinter GUI, My application having install button when user click install, It will start one GUI installation script and exit my application This my task.. The problem was the installation script started but control will be transfered to other window ... when installation finished the GUI application will be closed.. code: os.system("ls -l") & root.destroy when execute a command "ls -l " and application will be closed But os.system("top") & root.destroy Control will the transferred to the other-window, "top" closed means application will be closed.. plz..help me.. I checked also the command as background process.. like os.system("top &") & root.destroy Advance thanks Regards Ganesh. -- Did I learn something today? If not, I wasted it. From alan.gauld at btinternet.com Sat Feb 19 05:04:02 2011 From: alan.gauld at btinternet.com (ALAN GAULD) Date: Sat, 19 Feb 2011 10:04:02 +0000 (GMT) Subject: Python-os. Command Execution In-Reply-To: References: Message-ID: <67901.19503.qm@web86702.mail.ird.yahoo.com> > when user click install, It will start one GUI installation script and > exit my application > > This my task.. The problem was the installation script started but > control will be transfered to > > other window ... when installation finished the GUI application will be >closed.. > > code: > > os.system("ls -l") & root.destroy > First question is, why are you using the bitwise and operator to manage execution status. This is Python not C. Use clear logic that erflects what you are trying to do.( Especially if you only post code fragments.) if os.system('ls -l') != 0 : root.destroy() Is much more obvious in intent. > when execute a command "ls -l " and application will be closed Only if os.system returns an error code > os.system("top") & root.destroy > > Control will the transferred to the other-window, "top" closed means > application will be closed.. plz..help me.. I have no idea what other window you are referring to. Is it the OS console that top runs in? Have you checked the return code of os.system to see if it returns cleanly (ie a 0) or if it returns an error? You might find it better to use the subprocess module instead of os.system. There is more flexibilityy and control available there. > I checked also the command as background process.. like os.system("top > &") & root.destroy And what happened? We need a bit more context and you need to do a bity more debugging. Starting with getting rid of the bitwise and "trick" from C. All it does here is make it hard to understand whats happening. HTH, Alan G. Author of the Learn to Program web site http://www.alan-g.me.uk/ From misnomer at gmail.com Sat Feb 19 06:00:59 2011 From: misnomer at gmail.com (Nicholas Devenish) Date: Sat, 19 Feb 2011 11:00:59 +0000 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> <4d5f6352$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19/02/2011 07:41, Westley Mart?nez wrote: > Simply remove 'dvorak-' to get qwerty. It allows you to use the right > Alt key as AltGr. For example: > AltGr+' i = ? > AltGr+c = ? > AltGr+s = ? > > I don't work on Windows or Mac enough to have figured out how to do on > those platforms, but I'm sure there's a simple way. > Again, it's the funky symbols that would be difficult to input. On mac, the acute accent is Alt-e + vowel, so Alt-e i. This seems to work universally, regardless of gui application or terminal. I don't work with X applications enough to know if they work there, however. From misnomer at gmail.com Sat Feb 19 06:10:01 2011 From: misnomer at gmail.com (Nicholas Devenish) Date: Sat, 19 Feb 2011 11:10:01 +0000 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4d5e493a$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> <4d5e493a$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/02/2011 10:26, Steven D'Aprano wrote: > > Agreed. I'd like Python to support proper mathematical symbols like ? for > float('inf'), ? for not-equal, ? for greater-than-or-equal, and ? for > less-than-or-equal. > This would be joyful! At least with the subset of operations that already exist/exist as operators, the possibility of using these wouldn't affect anyone not using them (like the set/intersection notation mentioned in another post). I'm not very optimistic about anything like this ever being accepted into python main, however (I can't imagine it being terribly complicated to add to the accepted language, though). From googler.1.webmaster at spamgourmet.com Sat Feb 19 06:32:37 2011 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sat, 19 Feb 2011 03:32:37 -0800 (PST) Subject: Python leaks in cyclic garbage collection References: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> Message-ID: <9bc96dec-738b-438e-b2f5-0c2316a78e2a@t8g2000vbd.googlegroups.com> Thanks for your answers! They really helped me out!! :) From jkn_gg at nicorp.f9.co.uk Sat Feb 19 06:36:14 2011 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Sat, 19 Feb 2011 03:36:14 -0800 (PST) Subject: Making Line Graphs References: Message-ID: <3b2828d6-b4e7-4bef-be5e-bcf9785513cd@n10g2000yqf.googlegroups.com> Graphviz? http://www.graphviz.org/ HTH Jon N From roy at panix.com Sat Feb 19 07:40:20 2011 From: roy at panix.com (Roy Smith) Date: Sat, 19 Feb 2011 07:40:20 -0500 Subject: How to use Python well? References: <87d3moc0y2.fsf@benfinney.id.au> <878vxcbudn.fsf@benfinney.id.au> <874o80bsou.fsf@benfinney.id.au> Message-ID: In article , Jorgen Grahn wrote: > Some disagreement here. There are typographical features in > nroff/troff today which you don't get in web browsers: ligatures and > hyphenation for example. Saying that HTML doesn't have ligatures and hyphenation is kind of like saying Python is a bad programming language because it doesn't come in purple. Yes, n/troff does ligatures and hyphenation. Are such things really essential for an on-line reference manual? The ligatures, clearly not, since what most of us are talking about here are the plain-text renditions you get with the on-line "man" output. Hyphenation? I suppose it has some value for this kind of stuff, but it can also be a pain. What happens when you're grepping the man page for "egregious" and can't find it because it got hyphenated? No, those are things you want for typesetting documents, not for browsing on-line reference material. And I can't imagine anybody using troff for typesetting today. I'm sure there are a few people who will pop out of the woodwork insisting they do, but when it comes to typesetting, "I want a tool, not a hobby". From michael at stroeder.com Sat Feb 19 09:52:14 2011 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Sat, 19 Feb 2011 15:52:14 +0100 Subject: ANN: python-ldap-2.3.13 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.3.13 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Note: This is the last release with this feature set. From now on only very urgent fixes are going into release series 2.3.x. Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.3.13 2011-02-19 Changes since 2.3.12: Modules/ * Correct #ifdef-statement for LDAP_OPT_X_TLS_CRLFILE in constants.c fixes build with older OpenLDAP libs * Support for LDAP_OPT_DEFBASE (see SF#3072016, thanks to Johannes) From gelonida at gmail.com Sat Feb 19 10:06:19 2011 From: gelonida at gmail.com (Gelonida) Date: Sat, 19 Feb 2011 16:06:19 +0100 Subject: QWebView: notify python when I clicked on a certain web eleemnt Message-ID: I have a web page (existing page, can't modify it) and I would like to browse it in a QtWebview. (This is already working) Now I Wonder how I could achieve following behaviour: When I click on a certain element e.g. "" I would like to notify my python script. What is important: I don't want to change anything else in the web pages behaviour (This means if clicking on this element will call some java script functions, load a pag, then this should still happen. What is the correct way to do it? Thanks in advance for any suggestions From gelonida at gmail.com Sat Feb 19 10:07:10 2011 From: gelonida at gmail.com (Gelonida) Date: Sat, 19 Feb 2011 16:07:10 +0100 Subject: QWebView: Get coordinates of an element and simulate a relative to this position. Message-ID: WHht I wondered is following: Let's assume I use a QWebView, As soon as the page is loaded ( loadFinished signal) I'd like to identify a certain element with findFirstElement(), get it's coordinates (and size) calculate some related coordinates (for example 20 pixel above the top left corner of this element and clcik there. SO my questions: - how can I get the coordinate of an element, that I found with findFirstElement() - how can I click in the browser window relative to the coordinate previously obtained Thanks in advance for any suggestions ideas. From gelonida at gmail.com Sat Feb 19 10:07:24 2011 From: gelonida at gmail.com (Gelonida) Date: Sat, 19 Feb 2011 16:07:24 +0100 Subject: How to log certain web requests. Message-ID: Hi, I created a small browser with QWebview I subclassed QNetworkAccessManager with a customized version and set it as NetworAccessManager By adding a print / log statement in the createRequestMethod I am able to log, which requests are performed. What I would be interested in is however to to write the of some post requests and the data returned from the server into a log file. How can I do this? thanks in advance for any ideas? From goraviads at gmail.com Sat Feb 19 10:48:18 2011 From: goraviads at gmail.com (Vanitha) Date: Sat, 19 Feb 2011 07:48:18 -0800 (PST) Subject: Hai Simple To Make Ideas and Earn Money Message-ID: <793c2498-0533-4ba8-aa19-f4c1aec6973c@i39g2000prd.googlegroups.com> http://adf.ly/YOhx http://adf.ly/YOhx http://adf.ly/YOhx From me+list/python at ixokai.io Sat Feb 19 11:17:38 2011 From: me+list/python at ixokai.io (Stephen Hansen) Date: Sat, 19 Feb 2011 08:17:38 -0800 Subject: Python-os. Command Execution In-Reply-To: References: Message-ID: <4D5FED22.4090804@ixokai.io> On 2/19/11 1:44 AM, Ganesh Kumar wrote: > os.system("ls -l") & root.destroy "&" here doesn't do what you think it does. Its a bitwise AND operator, which is not the same thing as you may be expecting from other languages. In Python, you'd do something more like: os.system("ls -l") and root.destroy() But that's bad Python. First, let's look at what os.system actually returns: >>> import os >>> help(os.system) system(...) system(command) -> exit_status Execute the command (a string) in a subshell. Now, an exit status of 0 is actually generally considered a success, while 1-200odd is a failure. Now, if you want to run 'root.destroy()' if and only if the 'ls -l' command fails, you could do the above with an 'and'. Python DOES short-circuit its logical AND's, so the root.destroy() will NOT be run if ls -l succeeds (returns 0)... but really. That's _very_ cryptic. Its much better to do: if os.system("ls -l") != 0: root.destroy() (You could simply say 'if not os.system("ls -l")', but in this context where the more unusual behavior of '0 is true, >0 is false' which is opposite of what is normal in Python, I prefer to explicitly spell it out) If you instead mean the "&" to simply separate the statements, so that after the os.system is done, then regardless of the outcome root.destroy is called-- then... just separate the statements. os.system("ls -l") root.destroy() You can use them on the same line with a semicolon if you really must. But don't do that. :-) Now, all of that said -- I'm not sure what exactly is going WRONG with your program. You said GUI, and perhaps that's the problem? If you are calling a unix interactive command line program from within a GUI context, things are quite likely to go wrong unless you do a lot of extra work. Are you expecting a new console window to pop up for 'top' and for that to run on its own? If so -- that won't happen on its own or with a single function call sort of easy way. What OS are you on? What are you actually trying to do here? -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 487 bytes Desc: OpenPGP digital signature URL: From eaglebalti at gmail.com Sat Feb 19 12:02:54 2011 From: eaglebalti at gmail.com (Ashraf Ali) Date: Sat, 19 Feb 2011 09:02:54 -0800 (PST) Subject: Hello Friends Message-ID: Would you like to know about indian acttractive actresses. You can know about their life.Would you like to remain informed about latest News. So, just visit the following websites www.newsbeam.blogspot.com www.hotpics00.blogspot.com www.onlinegames786.blogspot.com www.tvlive00.blogspot.com www.funnyvids00.blogspot.com From anikom15 at gmail.com Sat Feb 19 12:10:01 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Sat, 19 Feb 2011 09:10:01 -0800 Subject: How to use Python well? In-Reply-To: References: <87d3moc0y2.fsf@benfinney.id.au> <878vxcbudn.fsf@benfinney.id.au> <874o80bsou.fsf@benfinney.id.au> Message-ID: <1298135401.2493.11.camel@localhost.localdomain> On Sat, 2011-02-19 at 07:40 -0500, Roy Smith wrote: > In article , > Jorgen Grahn wrote: > > > Some disagreement here. There are typographical features in > > nroff/troff today which you don't get in web browsers: ligatures and > > hyphenation for example. > > Saying that HTML doesn't have ligatures and hyphenation is kind of like > saying Python is a bad programming language because it doesn't come in > purple. > > Yes, n/troff does ligatures and hyphenation. Are such things really > essential for an on-line reference manual? The ligatures, clearly not, > since what most of us are talking about here are the plain-text > renditions you get with the on-line "man" output. > > Hyphenation? I suppose it has some value for this kind of stuff, but it > can also be a pain. What happens when you're grepping the man page for > "egregious" and can't find it because it got hyphenated? > > No, those are things you want for typesetting documents, not for > browsing on-line reference material. And I can't imagine anybody using > troff for typesetting today. I'm sure there are a few people who will > pop out of the woodwork insisting they do, but when it comes to > typesetting, "I want a tool, not a hobby". But you can't seriously say that authoring HTML is effective. Sure, outputting HTML is fine, but as for writing the source, troff, docbook, sphinx, even TeX, etc, is superior to HTML simply because HTML was designed for web pages and those others were designed specifically for documentation (not TeX, but that's another story). I hate writing HTML, it's a pain in the neck. But anyways, I find it easier to simply type "man sigaction" than to search around on google all day for a handful of facts and a truckload of opinions, as do I find it easier to type "help(os.path)" than have to open my browser, click on the python doc bookmark, search for os.path, wait for the search results, and click on it. This is just what I find easier though, and I think using tools that output HTML, groff, LaTeX, etc should continued to be used. From wdepli at mikrotec.com Sat Feb 19 12:25:12 2011 From: wdepli at mikrotec.com (Doug Epling) Date: Sat, 19 Feb 2011 12:25:12 -0500 Subject: newbie question about PYTHONPATH In-Reply-To: References: Message-ID: <42T7p.657052$Bh.208707@en-nntp-12.dc1.easynews.com> The best way I have found is to place that definition of your PYTHONPATH in your .bash_profile in your home directory and export it from there. PYTHONPATH=/home/foo/prog/learning_python export PYTHONPATH This way your PYTHONPATH is picked up each time you log on. You might have to restart IDLE for the changes you mention below to take effect. On 2/15/2011 12:49 PM, Tim Hanson wrote: > I am to the point in _Learning_Python_ where functions are introduced. > > I decided to experiment by putting a function into a file and importing it > into Idle. Of course, Idle couldn't find it, so I executed the following > command in Bash: > > PYTHONPATH=/home/foo/prog/learning_python > export PYTHONPATH > env | grep PYTHONPATH > > ~$PYTHONPATH=/home/foo/prog/learning_python > > Idle still won't find it. I'm doing something wrong? From roy at panix.com Sat Feb 19 12:46:13 2011 From: roy at panix.com (Roy Smith) Date: Sat, 19 Feb 2011 12:46:13 -0500 Subject: How to use Python well? References: <87d3moc0y2.fsf@benfinney.id.au> <878vxcbudn.fsf@benfinney.id.au> <874o80bsou.fsf@benfinney.id.au> Message-ID: In article , Westley Mart??nez wrote: > But you can't seriously say that authoring HTML is effective. By hand? No of course not. That's why we have things like wikis and CMS's, markup languages like ReST, TeX-to-HTML converters, and so on. But, we're getting way off topic for a Python forum. The original question was along the lines of "How do I write good Python?". I think we're all in agreement that somewhere in the answer to that has to be, "Provide documentation which is useful to your users, and keep it updated as the code changes". Beyond that, I think we need to move this to comp.text.religion. From andrea.crotti.0 at gmail.com Sat Feb 19 13:22:46 2011 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sat, 19 Feb 2011 19:22:46 +0100 Subject: newbie question about PYTHONPATH In-Reply-To: <42T7p.657052$Bh.208707@en-nntp-12.dc1.easynews.com> References: <42T7p.657052$Bh.208707@en-nntp-12.dc1.easynews.com> Message-ID: Il giorno 19/feb/2011, alle ore 18.25, Doug Epling ha scritto: > The best way I have found is to place that definition of your PYTHONPATH in your .bash_profile in your home directory and export it from there. > > PYTHONPATH=/home/foo/prog/learning_python > > export PYTHONPATH > > This way your PYTHONPATH is picked up each time you log on. You might have to restart IDLE for the changes you mention below to take effect. Yes but like this you overwrite it export PYTHONPATH=/your/path:$PYTHONPATH is much more safe to use From anikom15 at gmail.com Sat Feb 19 14:00:22 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Sat, 19 Feb 2011 11:00:22 -0800 Subject: newbie question about PYTHONPATH In-Reply-To: References: <42T7p.657052$Bh.208707@en-nntp-12.dc1.easynews.com> Message-ID: <1298142022.5817.0.camel@localhost.localdomain> On Sat, 2011-02-19 at 19:22 +0100, Andrea Crotti wrote: > Il giorno 19/feb/2011, alle ore 18.25, Doug Epling ha scritto: > > > The best way I have found is to place that definition of your PYTHONPATH in your .bash_profile in your home directory and export it from there. > > > > PYTHONPATH=/home/foo/prog/learning_python > > > > export PYTHONPATH > > > > This way your PYTHONPATH is picked up each time you log on. You might have to restart IDLE for the changes you mention below to take effect. > > Yes but like this you overwrite it > export PYTHONPATH=/your/path:$PYTHONPATH > > is much more safe to use It's even safer to use export PYTHONPATH=$PYTHONPATH:/your/path From piet at vanoostrum.org Sat Feb 19 15:22:20 2011 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 19 Feb 2011 16:22:20 -0400 Subject: return an object of a different class References: <8bc3505b-b050-4215-b5ce-df78f308042d@n10g2000yqf.googlegroups.com> Message-ID: Richard Thomas writes: > If you don't want to use a factory function I believe you can do this: > > class MyNumber(object): > def __new__(cls, n): > if n <= 100: > cls = SmallNumbers > else: > cls = BigNumbers > return object.__new__(cls, n) But you have to be aware that the initializers are not called in this way. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonartikelen op http://www.zylja.com From jeremy at jeremysanders.net Sat Feb 19 15:45:36 2011 From: jeremy at jeremysanders.net (Jeremy Sanders) Date: Sat, 19 Feb 2011 20:45:36 +0000 Subject: Making Line Graphs References: Message-ID: spam head wrote: > Does anybody have any recommendations for a good program from > generating these simple graphs? Have a look at Veusz, written in python: http://home.gna.org/veusz/ (I am the lead author). Jeremy From cs at zip.com.au Sat Feb 19 17:27:24 2011 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 20 Feb 2011 09:27:24 +1100 Subject: How to use Python well? In-Reply-To: References: Message-ID: <20110219222723.GA25807@cskk.homeip.net> On 18Feb2011 22:28, Roy Smith wrote: | In article <878vxcbudn.fsf at benfinney.id.au>, | Ben Finney wrote: | | > This collection of a great deal of documentation for the operating | > system into a single ???manual??? is one reason why users like man pages so | > much: we want to find anything installed on the system documented in | > that one place. | | What made man pages such a great technology back in the 70's was exactly | what Ben is saying. Everything was on-line and instantly available for | quick reference. Not to mention that you could use man as just another | cog in the unix toolset and do things like grep all of /usr/man for a | term (or an error message which appeared and you didn't know what had | produced it). These were astonishing advances in usability vs. having | printed manuals (which may or may not have been available to you). | | But, today we have such better tools available. HTML, for example. | Whether it's a wiki or the generated output of sphinx/doxygen/etc, HTML | provides for a much richer presentation. Which is more convenient: | having the signal(3) man page reference "sigaction(2)" textually, or | having it be a clickable link that can take me right there? HTML also | gives you much greater formatting flexibility than what's still | basically 35-year old nroff. But HTML is just presentation. There are _plenty_ of manual page renderers that write HTML. (Example: http://www.FreeBSD.org/cgi/man.cgi) Complete with clickable links to other manual pages etc. That can all be done automatically. And has _nothing_ to do with the source being in nroff format. And the source needn't be in nroff format, either. I have a bunch of man pages in POD format, which renders to an assortment of formats including nroff output. Your argument above is a fine argument for saying that HTML is a very valuable presentation format, especially if well cross referenced. But it is irrelevant to the usefulness of man pages. | If, for whatever reason, you're still wed to plain text, even info gives | you much better capabilities than man. At least you get basic stuff | like menus, document hierarchy, cross-linking, and browsing history. Any yet I (and others, based on stuff I've seen) find info to be a disaster. Why? - it forces the reader to use a non-standard pager to look at info, typically the utterly weird one that comes with the info command. The user using a terminal _should_ get to use their own pager because their fingers know how to drive it. Info, in its tiny pieces of text linked to other tiny pieces of text form, does not lend itself to this and the browser it does offer on a terminal is arcane. But see below (*). - the info pages end up as a scattering of tiny cross linked (if you're lucky) pieces with little information on one place/page. So you can't, for example, stand at the top of the doco page and search for a term. Frankly, info is usually a step backward, speaking as a reader. * I grew enraged at the prevalence of "GNU" unix tools with only info for doco, and no manual pages or manual pages that said "we don't put anything useful here, go read the info pages, the stuff here may not even be maintained" (I'm serious - see the bottom of a lot of the rather trite manual pages that ship with GNU this/that/the-other). So enraged that I wrote a couple of tools called info2pod and info2man that read postcompiled info output (the binary-mixed-with-text stuff info files ship as, post install) and join it all up again into a single flat text output that _can_ be paged and searched. And a modified "man" command that can include info dirs in the $MANPATH and thus present info as a man page. It is a little ugly, but at least it clubs info into usability. Example: % man screen 1: /usr/share/man/man1/screen.1.bz2 2: /usr/share/info/screen.info-2.bz2 3: /usr/share/info/screen.info-4.bz2 4: /usr/share/info/screen.info-5.bz2 5: /usr/share/info/screen.info-1.bz2 6: /usr/share/info/screen.info-3.bz2 7: /usr/share/info/screen.info.bz2 which entry? Choosing (1) gets you "man screen" as usual, choosing (7) gets you the whole screen info stuff flattened and presented as a single page, where you can _search_ for what you want. URL: http://www.cskk.ezoshosting.com/cs/css/#key-doc | I'm not saying that help text is the be-all and end-all for | documentation. I'm just saying that if you're going to do more than | help text, it's hard to imagine putting any effort into producing man | pages. Hard for you, maybe. As someone whole consistently finds well written (terse yet complete) man pages _much_ more useful than many other supposed documentation, I find it hard to imagine lack of man pages as other than a failure. There are exceptions of course. The python doco at python.org is pretty good. Wikipedia is often very good. But many wikis and other "rich and easy to author" systems are awful. Incomplete and badly fragmented. A lot of that can be laid to "documentation as an afterthought" mentality, but I also feel that having a manual page as a _single_ item contributes a lot to getting it all down. Writing man pages in nroff is a bit tedious (though actually not all that hard). Generating man pages from POD or some other similarly friendly format is easy and desirable. | Except possibly as the automated output of some multi-target | documentation system which produces them as a by-product of producing | other, richer, formats. Tick. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It looked like documentation, so I threw it out. - unknown luser From cs at zip.com.au Sat Feb 19 17:32:16 2011 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 20 Feb 2011 09:32:16 +1100 Subject: How to use Python well? In-Reply-To: <1298135401.2493.11.camel@localhost.localdomain> References: <1298135401.2493.11.camel@localhost.localdomain> Message-ID: <20110219223216.GA29607@cskk.homeip.net> On 19Feb2011 09:10, Westley Mart?nez wrote: | But you can't seriously say that authoring HTML is effective. Sure, | outputting HTML is fine, but as for writing the source, troff, docbook, | sphinx, even TeX, etc, is superior to HTML simply because HTML was | designed for web pages and those others were designed specifically for | documentation (not TeX, but that's another story). I hate writing HTML, | it's a pain in the neck. Chuckle. The basics of HTML (H1, H2, P, I etc) are Very Very closely based on the [nt]roff -mm macro set. Quite useable, actually, for the basics. The tag closing etc is a PITA, I agree. Of course, in nroff you'd be going: .H1 A Level One Heading paragraph blah blah ... No tedious closing tags there! CCheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ (about SSSCA) I don't say this lightly. However, I really think that the U.S. no longer is classifiable as a democracy, but rather as a plutocracy. - H. Peter Anvin From ben+python at benfinney.id.au Sat Feb 19 18:42:44 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 20 Feb 2011 10:42:44 +1100 Subject: How to use Python well? References: <87d3moc0y2.fsf@benfinney.id.au> <878vxcbudn.fsf@benfinney.id.au> <874o80bsou.fsf@benfinney.id.au> Message-ID: <87zkpra8wb.fsf@benfinney.id.au> Westley Mart?nez writes: > I hate writing HTML, it's a pain in the neck. So do I. But I hate writing *roff markup even more. So I don't write either of those formats directly if I can avoid it. I write my man pages in either Docbook (using an XML editor) or reST (my default markup format these days), then convert to *roff. > But anyways, I find it easier to simply type "man sigaction" than to > search around on google all day for a handful of facts and a truckload > of opinions Right. The Unix manual system allows a consistent place for operating system documentation. That includes, but is not limited to, the commands to be typed at the command line. Please preserve that consistency by maintaining man pages for commands. -- \ ?I installed a skylight in my apartment. The people who live | `\ above me are furious!? ?Steven Wright | _o__) | Ben Finney From rdmoores at gmail.com Sat Feb 19 18:56:45 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Sat, 19 Feb 2011 15:56:45 -0800 Subject: IDLE won't wrap lines of text Message-ID: Vista Python 3.1.3 I can't figure out how to get IDLE to wrap text pasted in from, say, a newspaper article. Usually, a each paragraph will appear as one long unwrapped line, with no way to read the whole line, because no horizontal bar is created. I haven't found anything about this in either the options or the help. Thanks, Dick Moores From fmarshallxremove_the_x at acm.org Sun Feb 20 02:22:44 2011 From: fmarshallxremove_the_x at acm.org (Fred Marshall) Date: Sat, 19 Feb 2011 23:22:44 -0800 Subject: wxPython in the context of Eclipse Message-ID: <6j38p.658954$Bh.462529@en-nntp-12.dc1.easynews.com> I asked earlier: How do I use wxPython or wxGlade in the context of Eclipse? A link to a howto would be great! I guess nobody knows or cares to answer? :-( From charleskatter at gmail.com Sun Feb 20 02:40:55 2011 From: charleskatter at gmail.com (Katter Charles) Date: Sat, 19 Feb 2011 23:40:55 -0800 (PST) Subject: Grate opportunities to earn money from online! Message-ID: <513f347b-e1b7-446e-aa19-4973a0aeba78@m7g2000vbq.googlegroups.com> Want to earn money from online. There have huge information about online earning information. Visit?? Earn money by SEO optimization http://itearn.com/seo/ Earn money by bogging http://itearn.com/blogging/ Earn money by facebook and twitter http://Itearn.com/socialnetwork Online earning update news http://itearn.com/news/ I hope this all information will help you to get success in online competition. From python at rcn.com Sun Feb 20 03:08:58 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 20 Feb 2011 00:08:58 -0800 (PST) Subject: An amazing one-minute bit of fun at the interactive prompt Message-ID: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> >>> e = 10.0 ** -7; n = 0; z = c = complex(-0.75, e) >>> while abs(z) < 2.0: n += 1 z = z * z + c >>> n * e 3.1415926 Compute ? ? e by counting Mandlebrot set iterations :-) Raymond From python at rcn.com Sun Feb 20 03:11:32 2011 From: python at rcn.com (Raymond Hettinger) Date: Sun, 20 Feb 2011 00:11:32 -0800 (PST) Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> Message-ID: <8bc5a26c-5294-4e1c-b47b-0594dbc4f954@d28g2000yqc.googlegroups.com> > Compute ? ? e by counting Mandlebrot set iterations :-) That should be: pi plus-or-minus e Raymond From grigory.javadyan at gmail.com Sun Feb 20 04:07:07 2011 From: grigory.javadyan at gmail.com (Grigory Javadyan) Date: Sun, 20 Feb 2011 13:07:07 +0400 Subject: Unbinding a name referenced by an enclosing scope Message-ID: >From the Python Language Reference (v 3.1): > It is illegal to unbind a name referenced by an enclosing scope; the compiler will report a SyntaxError. But when I run the following code: a = 3 def x(): global a del(a) print(a) x() it works fine; and when I change the order of calls: x() print(a) I get a NameError, not a SyntaxError. Apparently, I'm not understanding the rule correctly. Can anyone explain it? Thanks. From __peter__ at web.de Sun Feb 20 05:05:46 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 20 Feb 2011 11:05:46 +0100 Subject: Unbinding a name referenced by an enclosing scope References: Message-ID: Grigory Javadyan wrote: >>From the Python Language Reference (v 3.1): > >> It is illegal to unbind a name referenced by an enclosing scope; the >> compiler will report a SyntaxError. > > But when I run the following code: > > a = 3 > def x(): > global a > del(a) > > print(a) > x() > > it works fine; and when I change the order of calls: > > x() > print(a) > > I get a NameError, not a SyntaxError. Apparently, I'm not > understanding the rule correctly. Can anyone explain it? Thanks. The line you quote is probably meant to describe the following: >>> def f(): ... a = 42 ... def g(): ... nonlocal a ... del a ... SyntaxError: can not delete variable 'a' referenced in nested scope Please file a documentation bug if you can come up with a clarification. From redhatter at gentoo.org Sun Feb 20 05:58:36 2011 From: redhatter at gentoo.org (Stuart Longland) Date: Sun, 20 Feb 2011 02:58:36 -0800 (PST) Subject: hmac module and key format Message-ID: <7aef1abd-397c-4eab-9901-93f8d27b8cb3@q40g2000prh.googlegroups.com> Hi, Maybe I'm completely dense with regards to the hmac module and HMAC in general, but I've searched and cannot find for the life of me the answer to this very basic question. What format does hmac require the key to be in? I have a key in hexadecimal, do I give it the hex? Do I decode that to binary and give it that? Do I try to figure out what passphrase generated the hex and give it that instead? Nowhere in the documentation does it appear to mention what form the key must take, or how you tell it what form it's in for it to "figure it out". If someone could enlighten me, I'd be most grateful. Regards, Stuart Longland From ben+python at benfinney.id.au Sun Feb 20 06:42:17 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 20 Feb 2011 22:42:17 +1100 Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> Message-ID: <87oc679bl2.fsf@benfinney.id.au> Raymond Hettinger writes: > Compute ? ? e by counting Mandlebrot set iterations :-) Very cool! I love ? nerdery. Raymond Hettinger writes: > > Compute ? ? e by counting Mandlebrot set iterations :-) > > That should be: pi plus-or-minus e It was in my reader. Perhaps your server has encoding trouble? -- \ Moriarty: ?Forty thousand million billion dollars? That money | `\ must be worth a fortune!? ?The Goon Show, _The Sale of | _o__) Manhattan_ | Ben Finney From no.email at nospam.invalid Sun Feb 20 07:01:20 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 20 Feb 2011 04:01:20 -0800 Subject: hmac module and key format References: <7aef1abd-397c-4eab-9901-93f8d27b8cb3@q40g2000prh.googlegroups.com> Message-ID: <7xzkpq52zz.fsf@ruckus.brouhaha.com> Stuart Longland writes: > What format does hmac require the key to be in? It's an arbitrary string. I have a key in hexadecimal, do I give it the hex? Do I decode that to binary and give it that? Probably yes. Do you have test vectors? See if they work. From martin at address-in-sig.invalid Sun Feb 20 08:03:05 2011 From: martin at address-in-sig.invalid (Martin Gregorie) Date: Sun, 20 Feb 2011 13:03:05 +0000 (UTC) Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> <87oc679bl2.fsf@benfinney.id.au> Message-ID: On Sun, 20 Feb 2011 22:42:17 +1100, Ben Finney wrote: > Raymond Hettinger writes: > >> Compute ? ? e by counting Mandlebrot set iterations :-) > > Very cool! I love ? nerdery. > > > Raymond Hettinger writes: > >> > Compute ? ? e by counting Mandlebrot set iterations :-) >> >> That should be: pi plus-or-minus e > > It was in my reader. Perhaps your server has encoding trouble? Same here (Pan reader, Fedora 14). -- martin@ | Martin Gregorie gregorie. | Essex, UK org | From gerald.britton at gmail.com Sun Feb 20 08:15:35 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Sun, 20 Feb 2011 08:15:35 -0500 Subject: Python 3.2 and html.escape function Message-ID: I see that Python 3.2 includes a new module -- html -- with a single function -- escape. I would like to know how this function differs from xml.sax.saxutils.escape and, if there is no difference (or only a minor one), what the need is for this new module and its lone function -- Gerald Britton From steve+comp.lang.python at pearwood.info Sun Feb 20 08:42:26 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Feb 2011 13:42:26 GMT Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> Message-ID: <4d611a42$0$29972$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Feb 2011 00:08:58 -0800, Raymond Hettinger wrote: >>>> e = 10.0 ** -7; n = 0; z = c = complex(-0.75, e) >>>> while abs(z) < 2.0: > n += 1 > z = z * z + c > >>>> n * e > 3.1415926 Absolutely brilliant! That alone justifies including complex as a built- in type. *wink* > Compute ? ? e by counting Mandlebrot set iterations :-) eps would be a better name than e. As I read it, ? ? e would be some number between 0.423310825130748 and 5.859874482048838, which isn't a terribly impressive approximation :) BTW, I see the symbol in your post as ? (pi), not ? (lowercase eth). -- Steven From steve+comp.lang.python at pearwood.info Sun Feb 20 08:56:16 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Feb 2011 13:56:16 GMT Subject: Python 3.2 and html.escape function References: Message-ID: <4d611d80$0$29972$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Feb 2011 08:15:35 -0500, Gerald Britton wrote: > I see that Python 3.2 includes a new module -- html -- with a single > function -- escape. I would like to know how this function differs from > xml.sax.saxutils.escape and, if there is no difference (or only a minor > one), what the need is for this new module and its lone function Unless the html API has changed radically since Python 3.2a, I believe you are mistaken. [steve at sylar ~]$ python3.2 Python 3.2a1 (r32a1:83318, Aug 12 2010, 02:17:22) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import html >>> help(html) which gives me the following information: Help on package html: NAME html - # This directory is a Python package. FILE /usr/local/lib/python3.2/html/__init__.py MODULE DOCS http://docs.python.org/library/html PACKAGE CONTENTS entities parser So html is not a module, but a package that includes two sub-modules, entities and parser. I see no sign of anything called "escape" in either the top level html package, or either of the sub-modules, and the word "escape" only appears twice in the whole package, both times as "unescape": [steve at sylar ~]$ cd /usr/local/lib/python3.2/html/ [steve at sylar html]$ ls entities.py __init__.py parser.py __pycache__ [steve at sylar html]$ grep -i escape *.py parser.py: attrvalue = self.unescape(attrvalue) parser.py: def unescape(self, s): So I don't know what you are looking at, but I don't believe it is the standard html package in the Python standard library. Perhaps you have accidentally shadowed it with your own html module? Try this: >>> import html >>> html.__file__ '/usr/local/lib/python3.2/html/__init__.py' -- Steven From __peter__ at web.de Sun Feb 20 09:33:39 2011 From: __peter__ at web.de (Peter Otten) Date: Sun, 20 Feb 2011 15:33:39 +0100 Subject: Python 3.2 and html.escape function References: <4d611d80$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 20 Feb 2011 08:15:35 -0500, Gerald Britton wrote: > >> I see that Python 3.2 includes a new module -- html -- with a single >> function -- escape. I would like to know how this function differs from >> xml.sax.saxutils.escape and, if there is no difference (or only a minor >> one), what the need is for this new module and its lone function > > Unless the html API has changed radically since Python 3.2a, I believe > you are mistaken. Adding a function is not /that/ radical, and it has happened, see http://docs.python.org/dev/py3k/library/html.html The check-in message that is linked there claims that html.escape() is supposed to replace cgi.escape() Side note: there has been a discussion whether it's a good idea to put a function into a package, see http://mail.python.org/pipermail/python-dev/2011-January/107635.html From gsowww at yahoo.co.uk Sun Feb 20 11:54:33 2011 From: gsowww at yahoo.co.uk (GSO) Date: Sun, 20 Feb 2011 16:54:33 +0000 Subject: Best way to gain root privileges In-Reply-To: References: <4D5C700E.8070609@web.de> <39c55f6d-7480-456d-87a4-05b34376aaf8@d16g2000yqd.googlegroups.com> <4D5ED557.3050006@web.de> Message-ID: > http://hal.freedesktop.org/docs/polkit/pkexec.1.html > http://hal.freedesktop.org/docs/polkit/polkit.8.html > http://www.freedesktop.org/wiki/Software/PolicyKit > > A python package: > > http://pypi.python.org/pypi?:action=search&term=polkit&submit=search > > But there is example python code here: > > http://hal.freedesktop.org/docs/polkit/polkit-apps.html > A quick note for completeness on policykit - it takes two config files to manage policykit (which threw me a bit), see pkexec, but see also pklocalauthority to authorise users: http://hal.freedesktop.org/docs/polkit/pklocalauthority.8.html http://mdzlog.alcor.net/2010/06/27/navigating-the-policykit-maze/ Also on the subject of creating/ running a daemon from init, a template for python code to do this here: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ From as at sci.fi Sun Feb 20 12:41:36 2011 From: as at sci.fi (Anssi Saari) Date: Sun, 20 Feb 2011 19:41:36 +0200 Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> <87oc679bl2.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > Raymond Hettinger writes: > >> Compute ? ? e by counting Mandlebrot set iterations :-) > > Very cool! I love ? nerdery. > > > Raymond Hettinger writes: > >> > Compute ? ? e by counting Mandlebrot set iterations :-) >> >> That should be: pi plus-or-minus e > > It was in my reader. Perhaps your server has encoding trouble? He (or rather Google) used iso-8859-7 as a character set, which is the Latin/Greek alphabet and definitely has pi at 0xF0. Not exactly a common character set though. Running a iso-8859-1 font in a terminal means I see a ? instead of pi... From gerald.britton at gmail.com Sun Feb 20 12:51:11 2011 From: gerald.britton at gmail.com (Gerald Britton) Date: Sun, 20 Feb 2011 12:51:11 -0500 Subject: Python 3.2 and html.escape function Message-ID: Forgot to include the reference: http://docs.python.org/dev/whatsnew/3.2.html html A new html module was introduced with only a single function, escape(), which is used for escaping reserved characters from HTML markup: >>> import html >>> html.escape('x > 2 && x < 7') 'x > 2 && x < 7' -- Gerald Britton From cjns1989 at gmail.com Sun Feb 20 13:10:53 2011 From: cjns1989 at gmail.com (Chris Jones) Date: Sun, 20 Feb 2011 13:10:53 -0500 Subject: How to use Python well? In-Reply-To: <20110219222723.GA25807@cskk.homeip.net> References: <20110219222723.GA25807@cskk.homeip.net> Message-ID: <20110220181053.GA4162@pavo.local> On Sat, Feb 19, 2011 at 05:27:24PM EST, Cameron Simpson wrote: [..] > Any yet I (and others, based on stuff I've seen) find info to be a > disaster. Why? > > - it forces the reader to use a non-standard pager to look > at info, typically the utterly weird one that comes with the info > command. On the rare occcasions I used it, navigation was such an uphill battle that I often forgot what I was looking for in the first place. > The user using a terminal _should_ get to use their own pager > because their fingers know how to drive it. I stumbled into this some time ago and never looked back: https://alioth.debian.org/projects/pinfo/ It was love at first sight since it actually has the good taste to use by default the same vi-like navigation key bindings I have set up for myself in the ELinks web browser, which I tend to favor over GUIs browsers when I'm reading html docs. When you need to do brutal force searches, you could also take a look at the vim ?info? plugin. On debian distributions, it is part of the ?vim-scripts? package and can be invoked by the ?:Info? Ex-mode command. You can then use the ?:helpgrep? command to create a list of matches that you can navigate in the same user-friendly way as you would use for the Vim help files. In a nutshell, instead of getting cross-eyed trying to locate the highlighted area on the screen to find the current match and hit some ?find next? button (or use any functionally similar mechanism) repeatedly, you are presented with a list of all your matches in their context. It is then just a matter of navigating to the one(s) that looks more promising and just hit enter to open the corresponding doc page in another Vim sub-window. > Info, in its tiny pieces of text linked to other tiny pieces of > text form, does not lend itself to this and the browser it does > offer on a terminal is arcane. That also happens with html docs, with the single page vs. chunked formats. I have been rather enraged myself when researching something or other and felt I'd hit the jackpot when I found the perfect document online, only to have to read through the whole thing anyway because only the chunked format was available, and save from downloading all the bits and pieces and somehow recreating the single page version, there was no way I could run a global search. My main criticism of the man format is that it does not provide both. Here's an example. Since I don't write bash scripts on a regular basis, I often have to refer to the bash documentation. If I use man, I can search for instance for ?SHELL BUILTIN? alright, but the trouble is that there are about a dozen matches in this giant man page before I actually get to the ?SHELL BUILTINS? section. The info format, on the other hand, provides and index of the builtins, where I quickly find precisely what I am looking for. Generally speaking, I find that man pages are fine for anything that's, well.. about one page and that I can display on one screen (that's 92 lines on my display) have has major limitations for anything much longer. > But see below (*). > > - the info pages end up as a scattering of tiny cross linked (if > you're lucky) pieces with little information on one place/page. > So you can't, for example, stand at the top of the doco page and > search for a term. Not sure which particular info manual(s) you are referring to. There are also info documents that are nicely structured.. with a table of contents, an index, and sections of manageable proportions that provided you don't use the ridiculous ?info? viewer, make on-screen reading a pleasure, especially when you have decided to read the manual cover to cover. GNU/screen is a good example. The gdb manual is another. Perhaps it's also a matter of who wrote the doc, how good he is at writing doc, and how much effort he put in designing and writing the doc. And tools that automate the conversion from man to info and back may also have something to do with this sorry state of affairs. > Frankly, info is usually a step backward, speaking as a reader. I am also speaking as a reader and I find that both the man and the info format (and html as well, for that matter) have their merits, and it's a question of choosing the right format, depending on the circumstances and what you are trying to do. > * I grew enraged at the prevalence of "GNU" unix tools with only info > for doco, and no manual pages or manual pages that said "we don't put > anything useful here, go read the info pages, the stuff here may not > even be maintained" (I'm serious - see the bottom of a lot of the > rather trite manual pages that ship with GNU this/that/the-other). Same here... Especially when adding insult to injury, your favorite distribution ships a man page that directs you to the info manual, but does not ship the info version due to licensing disagreements, and you have to download the info version from gnu.org, create your own debian package.. etc. etc. Depending on the particular info manual, this can be quite tricky, since the procedure is not well-documented :) and rather buggy. > So enraged that I wrote a couple of tools called info2pod and > info2man that read postcompiled info output (the > binary-mixed-with-text stuff info files ship as, post install) and > join it all up again into a single flat text output that _can_ be > paged and searched. And a modified "man" command that can include > info dirs in the $MANPATH and thus present info as a man page. It is > a little ugly, but at least it clubs info into usability. Example: > % man screen > 1: /usr/share/man/man1/screen.1.bz2 > 2: /usr/share/info/screen.info-2.bz2 > 3: /usr/share/info/screen.info-4.bz2 > 4: /usr/share/info/screen.info-5.bz2 > 5: /usr/share/info/screen.info-1.bz2 > 6: /usr/share/info/screen.info-3.bz2 > 7: /usr/share/info/screen.info.bz2 > which entry? > > Choosing (1) gets you "man screen" as usual, choosing (7) gets you the > whole screen info stuff flattened and presented as a single page, where > you can _search_ for what you want. > > URL: http://www.cskk.ezoshosting.com/cs/css/#key-doc Sounds more mature than my own messy ?solutions? to this problem. :-) > | I'm not saying that help text is the be-all and end-all for > | documentation. I'm just saying that if you're going to do more than > | help text, it's hard to imagine putting any effort into producing man > | pages. > Hard for you, maybe. As someone whole consistently finds well written > (terse yet complete) man pages _much_ more useful than many other > supposed documentation, I find it hard to imagine lack of man pages as > other than a failure. In an ideal doc world and where ?program? is a non-trivial piece of software, I would like to be able to think of ?program --help? as the condensed reference card, ?man program? as the detailed reference card, and.. something like info, html, etc. as the user guide, and depending on what I am doing, the bases would be covered. > There are exceptions of course. The python doco at python.org is > pretty good. Wikipedia is often very good. But many wikis and other > "rich and easy to author" systems are awful. Incomplete and badly > fragmented. A lot of that can be laid to "documentation as an > afterthought" mentality, but I also feel that having a manual page as > a _single_ item contributes a lot to getting it all down. Apples and oranges.. In the same spirit as Westley Mart?nez nicely put it a few posts back in this thread, my personal experience has led me to regard wiki's as just a tiny step up from having to google mailing list's archives and.. many steps backward from man or info. > Writing man pages in nroff is a bit tedious (though actually not all > that hard). Generating man pages from POD or some other similarly > friendly format is easy and desirable. Nothing as nice as man pages written from scratch, but I've had good results with ?help2man?. cj From roy at panix.com Sun Feb 20 13:22:05 2011 From: roy at panix.com (Roy Smith) Date: Sun, 20 Feb 2011 13:22:05 -0500 Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> <87oc679bl2.fsf@benfinney.id.au> Message-ID: In article <87oc679bl2.fsf at benfinney.id.au>, Ben Finney wrote: > Raymond Hettinger writes: > > > Compute ??? ??? e by counting Mandlebrot set iterations :-) > > Very cool! I love ??? nerdery. > > > Raymond Hettinger writes: > > > > Compute ?? ?? e by counting Mandlebrot set iterations :-) > > > > That should be: pi plus-or-minus e > > It was in my reader. Perhaps your server has encoding trouble? He was probably reading the nroff man page. (ducking and running) From martin at v.loewis.de Sun Feb 20 13:46:10 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 20 Feb 2011 19:46:10 +0100 Subject: An amazing one-minute bit of fun at the interactive prompt In-Reply-To: <4d611a42$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> <4d611a42$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D616172.9060209@v.loewis.de> > eps would be a better name than e. py> ? = 10.0 ** -7; n = 0; z = c = complex(-0.75, ?) py> while abs(z) < 2.0: ... n += 1 ... z = z * z + c ... py> ? = n * ? py> print(?) 3.1415926 Regards, Martin From ppearson at nowhere.invalid Sun Feb 20 13:59:45 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 20 Feb 2011 18:59:45 GMT Subject: hmac module and key format References: <7aef1abd-397c-4eab-9901-93f8d27b8cb3@q40g2000prh.googlegroups.com> <7xzkpq52zz.fsf@ruckus.brouhaha.com> Message-ID: <8sd6l1Ft7vU1@mid.individual.net> On Sun, 20 Feb 2011 04:01:20 -0800, Paul Rubin wrote: > Stuart Longland writes: >> What format does hmac require the key to be in? > > It's an arbitrary string. > > I have a key in hexadecimal, do I give it the hex? Do I decode that > to binary and give it that? > > Probably yes. Do you have test vectors? See if they work. Test case from http://www.faqs.org/rfcs/rfc2104.html : key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b key_len = 16 bytes data = "Hi There" data_len = 8 bytes digest = 0x9294727a3638bb1c13f48ef8158bfc9d Using the hmac module: >>> hmac.hmac_md5( "Hi There", 16*"\x0b" ) '\x92\x94rz68\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d' -- To email me, substitute nowhere->spamcop, invalid->net. From ben+python at benfinney.id.au Sun Feb 20 16:32:45 2011 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 21 Feb 2011 08:32:45 +1100 Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> <87oc679bl2.fsf@benfinney.id.au> Message-ID: <87k4gu9yte.fsf@benfinney.id.au> Anssi Saari writes: > Ben Finney writes: > > It [appeared correctly] in my reader. Perhaps your server has > > encoding trouble? > > He (or rather Google) used iso-8859-7 as a character set, which is the > Latin/Greek alphabet and definitely has pi at 0xF0. Not exactly a > common character set though. Running a iso-8859-1 font in a terminal > means I see a ? instead of pi... Another good reason to eschew legacy encodings and use a Unicode character encoding for all internet messages, like the extremely common UTF-8. Get to it, Raymond! :-) -- \ ?I knew things were changing when my Fraternity Brothers threw | `\ a guy out of the house for mocking me because I'm gay.? | _o__) ?postsecret.com, 2010-01-19 | Ben Finney From brendan.simon at etrix.com.au Sun Feb 20 17:05:11 2011 From: brendan.simon at etrix.com.au (Brendan Simon (eTRIX)) Date: Mon, 21 Feb 2011 09:05:11 +1100 Subject: wxPython in the context of Eclipse In-Reply-To: References: Message-ID: <4D619017.2090006@etrix.com.au> On 20/02/2011 10:00 PM, python-list-request at python.org wrote: > Subject: > wxPython in the context of Eclipse > From: > Fred Marshall > Date: > Sat, 19 Feb 2011 23:22:44 -0800 > > To: > python-list at python.org > > > I asked earlier: > > How do I use wxPython or wxGlade in the context of Eclipse? > > A link to a howto would be great! > > I guess nobody knows or cares to answer? Have you tried the wxPython mailing list. You will probably have more wxPython users to draw upon than this list ;-) I use Eclipse with wxPython and it works fine. You need to install the Eclipse PyDev module (which I presume you have already done). If I recall correctly, I had to specify the python interpreter to use. It added a whole lot of paths to the PYTHONPATH variable which caused me some grief. I ended up removing them all (or most of them) and it worked fine after that. Cheers, Brendan. -- Brendan Simon www.etrix.com.au -------------- next part -------------- An HTML attachment was scrubbed... URL: From georg at python.org Sun Feb 20 17:22:47 2011 From: georg at python.org (Georg Brandl) Date: Sun, 20 Feb 2011 23:22:47 +0100 Subject: [RELEASED] Python 3.2 Message-ID: <4D619437.7050507@python.org> On behalf of the Python development team, I'm delighted to announce Python 3.2 final release. Python 3.2 is a continuation of the efforts to improve and stabilize the Python 3.x line. Since the final release of Python 2.7, the 2.x line will only receive bugfixes, and new features are developed for 3.x only. Since PEP 3003, the Moratorium on Language Changes, is in effect, there are no changes in Python's syntax and built-in types in Python 3.2. Development efforts concentrated on the standard library and support for porting code to Python 3. Highlights are: * numerous improvements to the unittest module * PEP 3147, support for .pyc repository directories * PEP 3149, support for version tagged dynamic libraries * PEP 3148, a new futures library for concurrent programming * PEP 384, a stable ABI for extension modules * PEP 391, dictionary-based logging configuration * an overhauled GIL implementation that reduces contention * an extended email package that handles bytes messages * a much improved ssl module with support for SSL contexts and certificate hostname matching * a sysconfig module to access configuration information * additions to the shutil module, among them archive file support * many enhancements to configparser, among them mapping protocol support * improvements to pdb, the Python debugger * countless fixes regarding bytes/string issues; among them full support for a bytes environment (filenames, environment variables) * many consistency and behavior fixes for numeric operations For a more extensive list of changes in 3.2, see http://docs.python.org/3.2/whatsnew/3.2.html To download Python 3.2 visit: http://www.python.org/download/releases/3.2/ Please consider trying Python 3.2 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.2's contributors) From tjreedy at udel.edu Sun Feb 20 18:54:36 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 20 Feb 2011 18:54:36 -0500 Subject: IDLE won't wrap lines of text In-Reply-To: References: Message-ID: On 2/19/2011 6:56 PM, Richard D. Moores wrote: > Vista > Python 3.1.3 > > I can't figure out how to get IDLE to wrap text pasted in from, say, a > newspaper article. Usually, a each paragraph will appear as one long > unwrapped line, with no way to read the whole line, because no > horizontal bar is created. I haven't found anything about this in > either the options or the help. The IDLE editor was designed for writing Python code, not general text. It is expected that you will limit line lengths to what can be seen on your screen. -- Terry Jan Reedy From rhodri at wildebst.demon.co.uk Sun Feb 20 19:31:18 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 21 Feb 2011 00:31:18 -0000 Subject: IDLE won't wrap lines of text References: Message-ID: On Sat, 19 Feb 2011 23:56:45 -0000, Richard D. Moores wrote: > Vista > Python 3.1.3 > > I can't figure out how to get IDLE to wrap text pasted in from, say, a > newspaper article. Usually, a each paragraph will appear as one long > unwrapped line, with no way to read the whole line, because no > horizontal bar is created. I haven't found anything about this in > either the options or the help. I hate to ask, but why are you doing this? IDLE isn't a general-purpose editor, it's a programming editor specifically for Python, and as such it's entirely appropriate for it to discourage overly long lines. -- Rhodri James *-* Wildebeest Herder to the Masses From stef.mientki at gmail.com Sun Feb 20 19:55:09 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 21 Feb 2011 01:55:09 +0100 Subject: SQLite server using execnet ? Message-ID: <4D61B7ED.1080105@gmail.com> hello, knowing that SQllite is not a client/server database, still want to see if a simple client/server setup would solve my current problems for the moment (because I love the simplicity of SQLlite, and planned to go to a client / server database in the future) Now I wonder if anyone has considered to use Python execnet-module to realize a simple SLQlite client / server application. If I look at the documentation of execnet, (and I realize that I'm a great optimist) it would take between 20 and 50 lines of Python code. thanks very much for your opinions. cheers, Stef Mientki From bc at freeuk.com Sun Feb 20 20:08:27 2011 From: bc at freeuk.com (BartC) Date: Mon, 21 Feb 2011 01:08:27 -0000 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com><9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com><4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: "WestleyMart?nez" wrote in message news:mailman.202.1298081685.1189.python-list at python.org... > You have provided me with some well thought out arguments and have > stimulated my young programmer's mind, but I think we're coming from > different angles. You seem to come from a more math-minded, idealist > angle, while I come from a more practical angle. Being a person who has > had to deal with the ? in my last name What purpose does the ? serve in your last name, and how is it different from i? (I'd have guessed it indicated stress, but it looks Spanish and I thought that syllable was stressed anyway.) -- Bartc From rdmoores at gmail.com Sun Feb 20 20:41:12 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Sun, 20 Feb 2011 17:41:12 -0800 Subject: IDLE won't wrap lines of text In-Reply-To: References: Message-ID: On Sun, Feb 20, 2011 at 16:31, Rhodri James wrote: > On Sat, 19 Feb 2011 23:56:45 -0000, Richard D. Moores > wrote: > >> Vista >> Python 3.1.3 >> >> I can't figure out how to get IDLE to wrap text pasted in from, say, a >> newspaper article. Usually, a each paragraph will appear as one long >> unwrapped line, with no way to read the whole line, because no >> horizontal bar is created. I haven't found anything about this in >> either the options or the help. > > I hate to ask, but why are you doing this? ?IDLE isn't a general-purpose > editor, it's a programming editor specifically for Python, and as such it's > entirely appropriate for it to discourage overly long lines. Take a look at Dick Moores From richard at python.org Sun Feb 20 21:28:15 2011 From: richard at python.org (Richard Jones) Date: Mon, 21 Feb 2011 13:28:15 +1100 Subject: PyCon Australia 2011 - Call for Participation Message-ID: The second PyCon AU will be held in Sydney on the weekend of the 20th and 21st of August at the Sydney Masonic Center. http://pycon-au.org/ We are looking for proposals for Talks on all aspects of Python programming from novice to advanced levels; applications and frameworks, or how you have been involved in introducing Python into your organisation. We're especially interested in short presentations that will teach conference-goers something new and useful. Can you show attendees how to use a module? Explore a Python language feature? Package an application? We welcome first-time speakers; we are a community conference and we are eager to hear about your experience. If you have friends or colleagues who have something valuable to contribute, twist their arms to tell us about it! Please also forward this Call for Proposals to anyone that you feel may be interested. To find out more go to the official Call for Proposals page here: http://pycon-au.org/2011/conference/proposals/ The deadline for proposal submission is the 2nd of May. See you in Sydney in August! Richard Jones PyCon AU Program Chair From rhodri at wildebst.demon.co.uk Sun Feb 20 21:32:20 2011 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 21 Feb 2011 02:32:20 -0000 Subject: IDLE won't wrap lines of text References: Message-ID: On Mon, 21 Feb 2011 01:41:12 -0000, Richard D. Moores wrote: > On Sun, Feb 20, 2011 at 16:31, Rhodri James > wrote: >> On Sat, 19 Feb 2011 23:56:45 -0000, Richard D. Moores >> >> wrote: >> >>> Vista >>> Python 3.1.3 >>> >>> I can't figure out how to get IDLE to wrap text pasted in from, say, a >>> newspaper article. Usually, a each paragraph will appear as one long >>> unwrapped line, with no way to read the whole line, because no >>> horizontal bar is created. I haven't found anything about this in >>> either the options or the help. >> >> I hate to ask, but why are you doing this? IDLE isn't a general-purpose >> editor, it's a programming editor specifically for Python, and as such >> it's >> entirely appropriate for it to discourage overly long lines. > > Take a look at I see. I'd recommend the approach of sticking your source data in a separate text file (using a text editor rather than IDLE) in any case; it's much less of a pain to change what you are working on that way. -- Rhodri James *-* Wildebeest Herder to the Masses From rdmoores at gmail.com Sun Feb 20 21:51:38 2011 From: rdmoores at gmail.com (Richard D. Moores) Date: Sun, 20 Feb 2011 18:51:38 -0800 Subject: IDLE won't wrap lines of text In-Reply-To: References: Message-ID: On Sun, Feb 20, 2011 at 18:32, Rhodri James wrote: > On Mon, 21 Feb 2011 01:41:12 -0000, Richard D. Moores > wrote: > >> On Sun, Feb 20, 2011 at 16:31, Rhodri James >> wrote: >>> >>> On Sat, 19 Feb 2011 23:56:45 -0000, Richard D. Moores >>> >>> wrote: >>> >>>> Vista >>>> Python 3.1.3 >>>> >>>> I can't figure out how to get IDLE to wrap text pasted in from, say, a >>>> newspaper article. Usually, a each paragraph will appear as one long >>>> unwrapped line, with no way to read the whole line, because no >>>> horizontal bar is created. I haven't found anything about this in >>>> either the options or the help. >>> >>> I hate to ask, but why are you doing this? ?IDLE isn't a general-purpose >>> editor, it's a programming editor specifically for Python, and as such >>> it's >>> entirely appropriate for it to discourage overly long lines. >> >> Take a look at > > I see. ?I'd recommend the approach of sticking your source data in a > separate text file (using a text editor rather than IDLE) in any case; > it's much less of a pain to change what you are working on that way. Problem is I know of no text editor that can handle Japanese. Thanks, Dick From andre.roberge at gmail.com Sun Feb 20 22:38:39 2011 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Sun, 20 Feb 2011 19:38:39 -0800 (PST) Subject: IDLE won't wrap lines of text In-Reply-To: Message-ID: <912b8fa7-a04c-4690-a743-256dada375b3@glegroupsg2000goo.googlegroups.com> On Sunday, February 20, 2011 10:51:38 PM UTC-4, Dick Moores wrote: > On Sun, Feb 20, 2011 at 18:32, Rhodri James wrote: > > On Mon, 21 Feb 2011 01:41:12 -0000, Richard D. Moores > > wrote: > > > >> On Sun, Feb 20, 2011 at 16:31, Rhodri James > >> wrote: > >>> > >>> On Sat, 19 Feb 2011 23:56:45 -0000, Richard D. Moores > >>> > >>> wrote: > >>> > >>>> Vista > >>>> Python 3.1.3 > >>>> > >>>> I can't figure out how to get IDLE to wrap text pasted in from, say, a > >>>> newspaper article. Usually, a each paragraph will appear as one long > >>>> unwrapped line, with no way to read the whole line, because no > >>>> horizontal bar is created. I haven't found anything about this in > >>>> either the options or the help. > >>> > >>> I hate to ask, but why are you doing this? ?IDLE isn't a general-purpose > >>> editor, it's a programming editor specifically for Python, and as such > >>> it's > >>> entirely appropriate for it to discourage overly long lines. > >> > >> Take a look at > > > > I see. ?I'd recommend the approach of sticking your source data in a > > separate text file (using a text editor rather than IDLE) in any case; > > it's much less of a pain to change what you are working on that way. > > Problem is I know of no text editor that can handle Japanese. > > Thanks, > > Dick The editor in Crunchy (http://code.google.com/p/crunchy) appears to be working just fine with the sample code you posted (at least when using Python 3 - I got an error when using it to run the code with Python 2). That being said, I would not recommend it for heavy work.... An editor that seems to work just fine (although it took a long time to load the sample code) is SublimeText (http://www.sublimetext.com/) - version 2 alpha; it is becoming my editor of choice. Andr? From wuwei23 at gmail.com Sun Feb 20 23:52:36 2011 From: wuwei23 at gmail.com (alex23) Date: Sun, 20 Feb 2011 20:52:36 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> Message-ID: <728e0198-65e9-4f68-8d47-34eb795bc92f@q40g2000prh.googlegroups.com> rantingrick wrote: > You lack vision. And you lack education. > Evolution is the pursuit of perfection at the expense of anything and > everything! Evolution is the process by which organisms change over time through genetically shared traits. There is no 'perfection', there is only 'fitness', that is, survival long enough to reproduce. Fitness is not something any of your ideas possess. The rest of your conjecture about my opinions and beliefs is just pure garbage. You'd get far fewer accusations of being a troll if you stopped putting words into other peoples mouths; then we'd just think you're exuberantly crazy. Also, Enough! With! The! Hyperbole! Already! "Visionary" is _never_ a self-appointed title. From patx44 at gmail.com Mon Feb 21 01:28:21 2011 From: patx44 at gmail.com (patx) Date: Mon, 21 Feb 2011 01:28:21 -0500 Subject: fastPATX Bison is here! for your speedy and safe web browsing needs! Message-ID: fastPATX 7.0.0 codenamed Bison is now out! You can get it at patx.me/fastpatx. If you have never tried fastPATX your missing out on the pinnacle of Python and PyQt4 development. Try it, you'll like it, and maybe even learn something from it. It has been awhile since the last fastPATX release, but hopefully this release will re-spark the tiny fastPATX fan base. In Bison a lot has changed. The first thing you will notice is that everything is smoother. Downloads work way better then in previous releases, it is easier to view the source code of a page, and the interface has been completely redesigned. We also added tabbed browsing. But we didn?t just add tabbed browsing we made it fit perfectly into fastPATX so that it looks like it was there from the beginning. Note there //is// a screenshot on the site so you can see what has changed, you will like it. If you have any questions please just email me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From grigory.javadyan at gmail.com Mon Feb 21 01:43:44 2011 From: grigory.javadyan at gmail.com (Grigory Javadyan) Date: Mon, 21 Feb 2011 10:43:44 +0400 Subject: SQLite server using execnet ? In-Reply-To: <4D61B7ED.1080105@gmail.com> References: <4D61B7ED.1080105@gmail.com> Message-ID: Are you sure you'll still be able to guarantee the ACID'ity of transactions? What about performance? Also, what kind of load are you expecting? I believe this will choke under too much simultaneous queries. On Mon, Feb 21, 2011 at 4:55 AM, Stef Mientki wrote: > hello, > > knowing that SQllite is not a client/server database, > still want to see if a simple client/server setup would solve my current problems for the moment > (because I love the simplicity of SQLlite, > and planned to go to a client / server database in the future) > > Now I wonder if anyone has considered ?to use Python execnet-module to realize a simple SLQlite > client / server application. > > If I look at the documentation of execnet, > (and I realize that I'm a great optimist) > it would take between 20 and 50 lines of Python code. > > thanks very much for your opinions. > cheers, > Stef Mientki > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Mon Feb 21 02:16:05 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Feb 2011 07:16:05 GMT Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9051d82c-2f98-4ffa-a501-9e1ec259e474@o14g2000prb.googlegroups.com> <728e0198-65e9-4f68-8d47-34eb795bc92f@q40g2000prh.googlegroups.com> Message-ID: <4d621135$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Feb 2011 20:52:36 -0800, alex23 wrote: > Also, Enough! With! The! Hyperbole! Already! "Visionary" is _never_ a > self-appointed title. You only say that because you lack the vision to see just how visionary rantingrick's vision is!!!!1!11! Followups set to c.l.p. -- Steven From __peter__ at web.de Mon Feb 21 02:55:57 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 21 Feb 2011 08:55:57 +0100 Subject: [RELEASED] Python 3.2 References: Message-ID: Georg Brandl wrote: > On behalf of the Python development team, I'm delighted to announce > Python 3.2 final release. Congratulations for your first as release manager, and a big thank you to you and all who contributed to this realease. > Python 3.2 is a continuation of the efforts to improve and stabilize the > Python 3.x line. Since the final release of Python 2.7, the 2.x line > will only receive bugfixes, and new features are developed for 3.x only. > > Since PEP 3003, the Moratorium on Language Changes, is in effect, there > are no changes in Python's syntax and built-in types in Python 3.2. > Development efforts concentrated on the standard library and support for > porting code to Python 3. Highlights are: > > * numerous improvements to the unittest module > * PEP 3147, support for .pyc repository directories > * PEP 3149, support for version tagged dynamic libraries > * PEP 3148, a new futures library for concurrent programming > * PEP 384, a stable ABI for extension modules > * PEP 391, dictionary-based logging configuration > * an overhauled GIL implementation that reduces contention > * an extended email package that handles bytes messages > * a much improved ssl module with support for SSL contexts and certificate > hostname matching > * a sysconfig module to access configuration information > * additions to the shutil module, among them archive file support > * many enhancements to configparser, among them mapping protocol support > * improvements to pdb, the Python debugger > * countless fixes regarding bytes/string issues; among them full support > for a bytes environment (filenames, environment variables) > * many consistency and behavior fixes for numeric operations This is an impressive list. It looks like Python 3 is now ready for mass adoption :) From dickinsm at gmail.com Mon Feb 21 03:08:34 2011 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 21 Feb 2011 00:08:34 -0800 (PST) Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> Message-ID: <9bad625b-5478-47d4-842b-5c0cbfa7b5f7@o1g2000yqb.googlegroups.com> On Feb 20, 8:08?am, Raymond Hettinger wrote: > [...] > >>> n * e > > 3.1415926 > > Compute ? ? e by counting Mandlebrot set iterations :-) Very neat! Is it supposed to be obvious why this gives an approximation to pi? If so, I'll think about it a bit more; if not, do you have any references? Maybe you should have saved this for March 14th... Mark From stefan_ml at behnel.de Mon Feb 21 03:16:44 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 21 Feb 2011 09:16:44 +0100 Subject: [RELEASED] Python 3.2 In-Reply-To: <4D619437.7050507@python.org> References: <4D619437.7050507@python.org> Message-ID: Georg Brandl, 20.02.2011 23:22: > On behalf of the Python development team, I'm delighted to announce > Python 3.2 final release. >[...] > Please consider trying Python 3.2 with your code and reporting any bugs > you may notice to: > > http://bugs.python.org/ Note to packagers: This release has a critical bug in distutils that prevents .pyc files from being byte compiled to their proper location during installation, thus preventing them from being used. http://bugs.python.org/issue11254 Stefan From steve+comp.lang.python at pearwood.info Mon Feb 21 03:56:37 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Feb 2011 08:56:37 GMT Subject: Python 3.2 and html.escape function References: <4d611d80$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d6228c4$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sun, 20 Feb 2011 15:33:39 +0100, Peter Otten wrote: > Steven D'Aprano wrote: > >> On Sun, 20 Feb 2011 08:15:35 -0500, Gerald Britton wrote: >> >>> I see that Python 3.2 includes a new module -- html -- with a single >>> function -- escape. I would like to know how this function differs >>> from xml.sax.saxutils.escape and, if there is no difference (or only a >>> minor one), what the need is for this new module and its lone function >> >> Unless the html API has changed radically since Python 3.2a, I believe >> you are mistaken. > > Adding a function is not /that/ radical, and it has happened, see > > http://docs.python.org/dev/py3k/library/html.html Well, I just learned something, thank you. I was under the mistaken impression that adding new functionality after the first alpha release was not permitted by the Python devs. -- Steven From n00m at narod.ru Mon Feb 21 04:10:48 2011 From: n00m at narod.ru (n00m) Date: Mon, 21 Feb 2011 01:10:48 -0800 (PST) Subject: Python leaks in cyclic garbage collection References: <18b043d7-dd17-4e0a-963b-fbf9ed44488d@a28g2000vbo.googlegroups.com> Message-ID: <3d4c729d-bb17-4218-b289-b1bc2cb52f17@o20g2000yqk.googlegroups.com> > Wild guess: > maybe when python exits they are called but sys.stdout has already been closed and nothing gets written on it anymore. Certainly NOT. class Foo(): def __init__(self): self.b = Bar(self) def __del__(self): print "Free Foo" class Bar(): def __init__(self, f): self.f = f def __del__(self): print "Free Bar" f = Foo() print f.b.f.b.f.b.f.b.f.b.f.b.f.b.f.b.f print f.b.f.b.f.b.f.b.f.b.f.b.f.b.f.b.f.b *********Console output:*********** <__main__.Foo instance at 0x00AF7328> <__main__.Bar instance at 0x00AF7350> D:\v3> From jeanmichel at sequans.com Mon Feb 21 04:34:40 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 21 Feb 2011 10:34:40 +0100 Subject: Making Line Graphs In-Reply-To: References: Message-ID: <4D6231B0.6070303@sequans.com> spam head wrote: > I'm looking for an easy way to display simple line graphs generated by > a python program in Windows. It could be done from within the > program, or I could write the information out to a file and call an > external program. Either is fine. > > Does anybody have any recommendations for a good program from > generating these simple graphs? > http://matplotlib.sourceforge.net/ JM From redhatter at gentoo.org Mon Feb 21 05:27:36 2011 From: redhatter at gentoo.org (Stuart Longland) Date: Mon, 21 Feb 2011 02:27:36 -0800 (PST) Subject: hmac module and key format References: <7aef1abd-397c-4eab-9901-93f8d27b8cb3@q40g2000prh.googlegroups.com> <7xzkpq52zz.fsf@ruckus.brouhaha.com> <8sd6l1Ft7vU1@mid.individual.net> Message-ID: <42f27e22-70c3-45e1-ab74-2dcc791bdbaa@w9g2000prg.googlegroups.com> On Feb 21, 4:59?am, Peter Pearson wrote: > On Sun, 20 Feb 2011 04:01:20 -0800, Paul Rubin wrote: > > Stuart Longland writes: > >> What format does hmac require the key to be in? > > > It's an arbitrary string. ? > > > ? ? I have a key in hexadecimal, do I give it the hex? ?Do I decode that > > ? ? to binary and give it that? ? > > > Probably yes. ?Do you have test vectors? ?See if they work. > > Test case from http://www.faqs.org/rfcs/rfc2104.html: [...] > >>> hmac.hmac_md5( "Hi There", 16*"\x0b" ) > > '\x92\x94rz68\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d' No worries, thanks to both you Peter and Paul, I'll give this a shot. By the looks of things it is possible to just decode the hexadecimal to a binary string and give it that. I should perhaps elaborate on what I'm doing in case the specifics make a difference. I have a YubiKey which internally supports a challenge-response mode based on HMAC-SHA1. I've got a key, a sample challenge and the sample output which is included in the python-yubico module demos: https://github.com/yubico/python-yubico Before I worried about that though, I needed to have some kind of understanding as to how the hmac module was used. "Arbitrary string", sounds to me like I give it something akin to a passphrase, and that is hashed(?) to provide the symmetric key for the HMAC. Wikipedia seems to suggest it depends on the length of the key given, so if I give it a string that's exactly 160-bits (for HMAC-SHA1) it'll use it unmodified. Would that be a correct assertion? From duncan.booth at invalid.invalid Mon Feb 21 05:53:39 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Feb 2011 10:53:39 GMT Subject: IDLE won't wrap lines of text References: <912b8fa7-a04c-4690-a743-256dada375b3@glegroupsg2000goo.googlegroups.com> Message-ID: Andr? Roberge wrote: > On Sunday, February 20, 2011 10:51:38 PM UTC-4, Dick Moores wrote: >> Problem is I know of no text editor that can handle Japanese. >> > > The editor in Crunchy (http://code.google.com/p/crunchy) appears to be > working just fine with the sample code you posted (at least when using > Python 3 - I got an error when using it to run the code with Python > 2). That being said, I would not recommend it for heavy work.... > > An editor that seems to work just fine (although it took a long time > to load the sample code) is SublimeText (http://www.sublimetext.com/) > - version 2 alpha; it is becoming my editor of choice. > FWIW, Lugaru Epsilon (http://lugaru.com/) seems to handle it just fine though you do have to set it to use a fixed pitch font which has Japanese glyphs (MS Mincho was the only suitable font on my system but would suck for general editing). -- Duncan Booth http://kupuguy.blogspot.com From tim.wintle at teamrubber.com Mon Feb 21 06:07:47 2011 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 21 Feb 2011 11:07:47 +0000 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4D5E65A7.9030808@gmail.com> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <87lj1egifg.fsf@andromeda.clsnet.nl> <4d5e0708$0$10591$742ec2ed@news.sonic.net> <20110218075011.GD29770@pavo.local> <4D5E65A7.9030808@gmail.com> Message-ID: <1298286467.15746.120.camel@tim-laptop> On Fri, 2011-02-18 at 12:27 +0000, Ian wrote: > 2) Culture. In the West, a designer will decide the architecture of a > major system, and it is a basis > for debate and progress. If he gets it wrong, it is not a personal > disgrace or career limiting. If it is > nearly right, then that is a major success. In Japan, the architecture > has to be a debated and agreed. > This takes ages, costs lots, and ultimately fails. The failure is > because architecture is always a trade off - > there is no perfect answer. I find this really interesting - we spend quite a lot of time studying the Toyota production system and seeing how we can do programming work in a similar way, and it's worked fairly well for us (Kanban, Genchi Genbutsu, eliminating Muda & Mura, etc). I would have expected Japanese software to have worked quite smoothly, with continuous improvement taking in everybody's opinions etc - although I suppose that if production never starts because the improvements are done to a spec, rather than the product, it would be a massive hindrance. Tim Wintle From timothy.c.delaney at gmail.com Mon Feb 21 06:56:47 2011 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Mon, 21 Feb 2011 22:56:47 +1100 Subject: Python 3.2 and html.escape function In-Reply-To: <4d6228c4$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4d611d80$0$29972$c3e8da3$5496439d@news.astraweb.com> <4d6228c4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21 February 2011 19:56, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Sun, 20 Feb 2011 15:33:39 +0100, Peter Otten wrote: > > > Steven D'Aprano wrote: > > > >> On Sun, 20 Feb 2011 08:15:35 -0500, Gerald Britton wrote: > >> > >>> I see that Python 3.2 includes a new module -- html -- with a single > >>> function -- escape. I would like to know how this function differs > >>> from xml.sax.saxutils.escape and, if there is no difference (or only a > >>> minor one), what the need is for this new module and its lone function > >> > >> Unless the html API has changed radically since Python 3.2a, I believe > >> you are mistaken. > > > > Adding a function is not /that/ radical, and it has happened, see > > > > http://docs.python.org/dev/py3k/library/html.html > > Well, I just learned something, thank you. I was under the mistaken > impression that adding new functionality after the first alpha release > was not permitted by the Python devs. > Nope - it's after first beta that features are frozen, barring something important enough to convince the current release manager (with input from many others) that the release should go back to alpha status. I've followed a number of such discussions and the bar is set very high. Python is one of the few projects around these days that follows the nomenclature of: alpha: early release to test new features, everything subject to change; beta: feature-complete, but expected to contain bugs; people testing the beta version can rely on APIs not changing in the release version; release candidate: may be promoted to release with just a version change; any other changes should result in another release candidate. IIRC there have been one or two cases in the not-recent past where a release has been made which includes a bugfix not included in any RC (and I distinctly remember at least one brown paper bag release following just such a situation), but at least for the last few years on python-dev the release managers have been strongly against this. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From bugcy013 at gmail.com Mon Feb 21 07:06:55 2011 From: bugcy013 at gmail.com (Ganesh Kumar) Date: Mon, 21 Feb 2011 17:36:55 +0530 Subject: PY-Tkinter Title Bar Icon Message-ID: Hai.. I am new to python Tkinter..I want Title Bar Icon.. plz..Guide me to set up icon in Title Bar. Advance Thanks Thanks -Ganesh. -- Did I learn something today? If not, I wasted it. From jeanmichel at sequans.com Mon Feb 21 08:23:10 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 21 Feb 2011 14:23:10 +0100 Subject: return an object of a different class In-Reply-To: <960d5210-03a8-44ae-88cc-7c3cd6020e67@h40g2000pre.googlegroups.com> References: <960d5210-03a8-44ae-88cc-7c3cd6020e67@h40g2000pre.googlegroups.com> Message-ID: <4D62673E.8090800@sequans.com> alex23 wrote: > Jean-Michel Pichavant wrote: > >> You simply don't return inconsistent types with a return statement. This >> is a general rule in programming that has probably exceptions but >> regarding what you're saying, you clearly don't want to do that. >> > > I don't think they were intended to be inconsistent types, but > subclasses of the same type. Returning different subclasses is exactly > what a factory is for. And given Python's propensity for duck typing, > they don't even really need to be subclassed for the same object, they > just need the interface that is required. > > >> Immagine the following code: >> >> oNumber = MyNumbers(random.int(100)) # note that oNumber is not a >> MyNumbers instance... quite confusing don't you think ? >> oNumber. ... wait a minute, which methods am I allowed to call ??? >> SmallNumbers adn BigNumbers have differents methods. >> > > What if they have different implementations rather than methods? > The answer is quite simple, from a OOP POV, the factory class/function returns a MyNumber instance, not a SmallNumber nor BigNumber one. This is what the documentation should state. Note that SmallNumber and BigNumber instances are both MyNumber instances. But from a user POV, there's no need to know about Small and Big implementations. All you need to know is the base classe MyNumber methods. Regarding duck typing, it is all about implementing an interface that is not explicit. That way, factory functions return consistent types if they return instances with a common interface. That's perfectly legit. What is not legit, is to return different objects for which the caller has to test the type to know what attributes he can use. JM From lutheroto at gmail.com Mon Feb 21 08:33:08 2011 From: lutheroto at gmail.com (Luther) Date: Mon, 21 Feb 2011 05:33:08 -0800 (PST) Subject: "ImportError: No module named gobject" Message-ID: <6d45ceff-0219-4d06-a433-ebda52232caa@y26g2000yqd.googlegroups.com> I recently had to install 2.7.1 from source, and since then, I have been unable to run exaile, which comes with Trisquel 4.0. Here is the error message: Traceback (most recent call last): File "/usr/lib/exaile/exaile.py", line 52, in main() File "/usr/lib/exaile/exaile.py", line 49, in main exaile = main.Exaile() File "/usr/lib/exaile/xl/main.py", line 74, in __init__ self.mainloop_init() File "/usr/lib/exaile/xl/main.py", line 439, in mainloop_init import gobject ImportError: No module named gobject Is there some special way to compile Python? Do I have to install another Debian package? From hash.3g at gmail.com Mon Feb 21 08:39:19 2011 From: hash.3g at gmail.com (=?KOI8-R?B?98nUwczJyiD3z8zLz9c=?=) Date: Mon, 21 Feb 2011 15:39:19 +0200 Subject: "ImportError: No module named gobject" In-Reply-To: <6d45ceff-0219-4d06-a433-ebda52232caa@y26g2000yqd.googlegroups.com> References: <6d45ceff-0219-4d06-a433-ebda52232caa@y26g2000yqd.googlegroups.com> Message-ID: You should install python-gobject 2011/2/21 Luther > I recently had to install 2.7.1 from source, and since then, I have > been unable to run exaile, which comes with Trisquel 4.0. Here is the > error message: > > Traceback (most recent call last): > File "/usr/lib/exaile/exaile.py", line 52, in > main() > File "/usr/lib/exaile/exaile.py", line 49, in main > exaile = main.Exaile() > File "/usr/lib/exaile/xl/main.py", line 74, in __init__ > self.mainloop_init() > File "/usr/lib/exaile/xl/main.py", line 439, in mainloop_init > import gobject > ImportError: No module named gobject > > Is there some special way to compile Python? Do I have to install > another Debian package? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lutheroto at gmail.com Mon Feb 21 10:04:47 2011 From: lutheroto at gmail.com (Luther) Date: Mon, 21 Feb 2011 07:04:47 -0800 (PST) Subject: "ImportError: No module named gobject" References: <6d45ceff-0219-4d06-a433-ebda52232caa@y26g2000yqd.googlegroups.com> Message-ID: <14e8e955-23ba-4961-827c-e0453dbba9c4@o14g2000prb.googlegroups.com> I've tried installing pygtk, pygobject, and gobject-introspection from source, but none of them will compile, and nothing I install through synaptic has any effect. I've tried too many things to post all the details here, but I'll post any details on request. From duncan.booth at invalid.invalid Mon Feb 21 10:54:09 2011 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Feb 2011 15:54:09 GMT Subject: [RELEASED] Python 3.2 References: Message-ID: Georg Brandl wrote: > Please consider trying Python 3.2 with your code and reporting any bugs > you may notice to: > > http://bugs.python.org/ > It looks like this release breaks the builtin `input()` function on Windows by leaving a trailing '\r' on the end of the string. Reported as issue 11272: http://bugs.python.org/issue11272 -- Duncan Booth http://kupuguy.blogspot.com From gdamjan at gmail.com Mon Feb 21 11:09:12 2011 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 21 Feb 2011 17:09:12 +0100 Subject: QWebView: notify python when I clicked on a certain web eleemnt References: Message-ID: <9afa38-7ma.ln1@archaeopteryx.softver.org.mk> > I have a web page (existing page, can't modify it) and I would like > to browse it in a QtWebview. (This is already working) > > Now I Wonder how I could achieve following behaviour: > > When I click on a certain element e.g. "" > I would like to notify my python script. > > What is important: > I don't want to change anything else in the web pages behaviour (This > means if clicking on this element will call some java script > functions, load a pag, then this should still happen. You can inject JavaScript using the method QWebElement::evaluateJavaScript() Also you can insert a Python object in the JS runtime with QWebFrame::addToJavaScriptWindowObject() see here: http://pysnippet.blogspot.com/2010/01/calling-python-from-javascript-in- pyqts.html so make a Python object with some methods you'd wish to call, then evaluate some small JS that will bind the click event on your element to the method of the Python object. -- ?????? ((( http://damjan.softver.org.mk/ ))) Teaching a pig to sing wastes your time & annoys the pig. From rafe.kettler at gmail.com Mon Feb 21 11:30:19 2011 From: rafe.kettler at gmail.com (Rafe Kettler) Date: Mon, 21 Feb 2011 08:30:19 -0800 (PST) Subject: Python 3.2 References: Message-ID: On Feb 21, 10:54?am, Duncan Booth wrote: > Georg Brandl wrote: > > Please consider trying Python 3.2 with your code and reporting any bugs > > you may notice to: > > > ? ?http://bugs.python.org/ > > It looks like this release breaks the builtin `input()` function on Windows > by leaving a trailing '\r' on the end of the string. > > Reported as issue 11272:http://bugs.python.org/issue11272 > > -- > Duncan Boothhttp://kupuguy.blogspot.com Are fixes for these bugs going to wait until the next release (3.2.1 I guess) or will update as soon as the fixes are available? I want to know if I should be on the lookout for a better version of 3.2. Rafe From rmorgan466 at gmail.com Mon Feb 21 11:33:26 2011 From: rmorgan466 at gmail.com (Rita) Date: Mon, 21 Feb 2011 11:33:26 -0500 Subject: Converting from shell to python Message-ID: Hello, I have been using shell for a "long" time and I decided to learn python recently. So far I am liking it a lot especially the argparse module which makes my programs more professional like. Currently, I am rewriting my bash scripts to python so I came across a subprocess and environment problem. My bash script looks like this, #!/usr/bin/env bash export JAVA_HOME="/opt/java" export PROG="dbconn" export JAVA_ARGS="-Xmx16g" export ARGS="-out outdata.dat" $JAVA_HOME $JAVA_ARGS $PROG $ARGS To convert this into python I did something like this (which isn't working properly) #!/usr/bin/env python import subprocess,os def execute(): try: cmd="$JAVA_HOME $JAVA_ARGS $PROG $ARGS" cmd=cmd.split() p=subprocess.Popen([cmd],env={"JAVA_HOME":"/opt/java","PROG":"dbconn","JAVA_ARGS":"-Xmx16g","ARGS":"-out outdata.dat"}, stdout=subprocess.PIPE) except OSError, e: print >>sys.stderr," Execution failed: ",e return p.stdout So, I was wondering if this is the correct way of doing it? or is there an alternative? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From riteshn at gmail.com Mon Feb 21 12:02:08 2011 From: riteshn at gmail.com (Ritesh Nadhani) Date: Mon, 21 Feb 2011 09:02:08 -0800 Subject: Converting from shell to python In-Reply-To: References: Message-ID: Hello cmd is already a list after cmd.split(). So, suprocess.Popen(cmd, ....) On Mon, Feb 21, 2011 at 8:33 AM, Rita wrote: > Hello, > > I have been using shell for a "long" time and I decided to learn python > recently. So far I am liking it a lot especially the argparse module which > makes my programs more professional like. > > > Currently, I am rewriting my bash scripts to python so I came across a > subprocess and environment problem. > > My bash script looks like this, > > #!/usr/bin/env bash > > export JAVA_HOME="/opt/java" > export? PROG="dbconn" > export JAVA_ARGS="-Xmx16g" > export ARGS="-out outdata.dat" > > $JAVA_HOME $JAVA_ARGS $PROG $ARGS > > > To convert this into python I did something like this (which isn't working > properly) > > #!/usr/bin/env python > import subprocess,os > def execute(): > ? try: > > ??? cmd="$JAVA_HOME $JAVA_ARGS $PROG $ARGS" > ??? cmd=cmd.split() > > p=subprocess.Popen([cmd],env={"JAVA_HOME":"/opt/java","PROG":"dbconn","JAVA_ARGS":"-Xmx16g","ARGS":"-out > outdata.dat"}, > ???????? stdout=subprocess.PIPE) > ? except OSError, e: > ?? print >>sys.stderr," Execution failed: ",e > ?return p.stdout > > > So, I was wondering if this is the correct way of doing it? or is there an > alternative? > > > > > > > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Ritesh http://www.beamto.us From __peter__ at web.de Mon Feb 21 12:07:19 2011 From: __peter__ at web.de (Peter Otten) Date: Mon, 21 Feb 2011 18:07:19 +0100 Subject: Converting from shell to python References: Message-ID: Rita wrote: > Hello, > > I have been using shell for a "long" time and I decided to learn python > recently. So far I am liking it a lot especially the argparse module which > makes my programs more professional like. > > > Currently, I am rewriting my bash scripts to python so I came across a > subprocess and environment problem. > > My bash script looks like this, > > #!/usr/bin/env bash > > export JAVA_HOME="/opt/java" > export PROG="dbconn" > export JAVA_ARGS="-Xmx16g" > export ARGS="-out outdata.dat" > > $JAVA_HOME $JAVA_ARGS $PROG $ARGS > > > To convert this into python I did something like this (which isn't working > properly) > > #!/usr/bin/env python > import subprocess,os > def execute(): > try: > > cmd="$JAVA_HOME $JAVA_ARGS $PROG $ARGS" > cmd=cmd.split() Here you turn cmd into a list p=subprocess.Popen([cmd],env={"JAVA_HOME":"/opt/java","PROG":"dbconn","JAVA_ARGS":"- Xmx16g","ARGS":"-out and now you are wrapping it to [...], i. e. you get a list of list. Also, to enable shell expansion you have to invoke Popen(..., shell=True). > outdata.dat"}, > stdout=subprocess.PIPE) > except OSError, e: > print >>sys.stderr," Execution failed: ",e > return p.stdout > > > So, I was wondering if this is the correct way of doing it? or is there an > alternative? I think the easiest way is to avoid environment variables and use python variables instead, e. g. JAVA_HOME = "/opt/java" JAVA_ARGS = "-Xmx16g" #... cmd = [JAVA_HOME, JAVA_ARGS, ...] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) From stefan_ml at behnel.de Mon Feb 21 12:14:13 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 21 Feb 2011 18:14:13 +0100 Subject: Python 3.2 In-Reply-To: References: Message-ID: Rafe Kettler, 21.02.2011 17:30: > On Feb 21, 10:54 am, Duncan Booth wrote: >> Georg Brandl wrote: >>> Please consider trying Python 3.2 with your code and reporting any bugs >>> you may notice to: >> >>> http://bugs.python.org/ >> >> It looks like this release breaks the builtin `input()` function on Windows >> by leaving a trailing '\r' on the end of the string. >> >> Reported as issue 11272:http://bugs.python.org/issue11272 > > Are fixes for these bugs going to wait until the next release (3.2.1 I > guess) Yes. That's what "the next release" means. > or will update as soon as the fixes are available? You mean: as soon as someone writes a fix? > I want to know if I should be on the lookout for a better version of 3.2. Better test now and report any problems you find. (Actually, that's what the beta/RC phase was there for, but it's never too late to find a bug.) Stefan From info at wingware.com Mon Feb 21 12:26:01 2011 From: info at wingware.com (Wingware) Date: Mon, 21 Feb 2011 12:26:01 -0500 Subject: ANN: Wing IDE 4.0 Released Message-ID: <4D62A029.1020202@wingware.com> Hi, Wingware has released version 4.0 of Wing IDE, an integrated development environment designed specifically for the Python programming language. Wing IDE is a cross-platform Python IDE that provides a professional code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, a powerful graphical debugger, version control, unit testing, search, and many other features. **Changes in Version 4.0** Version 4.0 adds the following new major features: * Refactoring -- Rename and move symbols, and extract code to function or method * Find Uses -- Find all points of use of a symbol * Diff/Merge -- Graphical file and repository comparison and merge * Django Support -- Debug Django templates, run Django unit tests, and more * matplotlib Support -- Maintains live-updating plots in shell and debugger * Simplified Licensing -- Includes all OSes and adds Support+Upgrades subscriptions Complete Change Log: http://wingware.com/pub/wingide/4.0.0/CHANGELOG.txt Details on Licensing Changes: http://wingware.com/news/2011-02-16 **About Wing IDE** Wing IDE is an integrated development environment designed specifically for the Python programming language. It provides powerful editing, testing, and debugging features that help reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE can be used to develop Python code for web, GUI, and embedded scripting applications. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching beginning programming courses with Python. Version 4.0 of Wing IDE Professional includes the following major features: * Professional quality code editor with vi, emacs, and other keyboard personalities * Code intelligence for Python: Auto-completion, call tips, find uses, goto-definition, error indicators, refactoring, smart indent and rewrapping, and source navigation * Advanced multi-threaded debugger with graphical UI, command line interaction, conditional breakpoints, data value tooltips over code, watch tool, and externally launched and remote debugging * Powerful search and replace options including keyboard driven and graphical UIs, multi-file, wild card, and regular expression search and replace * Version control integration for Subversion, CVS, Bazaar, git, Mercurial, and Perforce * Integrated unit testing with unittest, nose, and doctest frameworks * Django support: Debugs Django templates, provides project setup tools, and runs Django unit tests * Many other features including project manager, bookmarks, code snippets, diff/merge tool, OS command integration, indentation manager, PyLint integration, and perspectives * Extremely configurable and may be extended with Python scripts * Extensive product documentation and How-Tos for Django, matplotlib, Plone, wxPython, PyQt, mod_wsgi, Autodesk Maya, and many other frameworks Please refer to http://wingware.com/wingide/features for a detailed listing of features by product level. System requirements are Windows 2000 or later, OS X 10.3.9 or later (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE supports Python versions 2.0.x through 3.2.x and Stackless Python. For more information, see the http://wingware.com/ **Downloads** Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial can be obtained directly from the product when launched. Wing IDE Pro -- Full-featured product: http://wingware.com/downloads/wingide/4.0 Wing IDE Personal -- A simplified IDE: http://wingware.com/downloads/wingide-personal/4.0 Wing IDE 101 -- For teaching with Python: http://wingware.com/downloads/wingide-101/4.0 **Purchasing and Upgrading** Wing 4.0 requires an upgrade for Wing IDE 2.x and 3.x users at a cost of 1/2 the full product pricing. Upgrade a license: https://wingware.com/store/upgrade Purchase a new license: https://wingware.com/store/purchase -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From mafunk at nmsu.edu Mon Feb 21 12:30:29 2011 From: mafunk at nmsu.edu (Matt Funk) Date: Mon, 21 Feb 2011 10:30:29 -0700 Subject: python and parsing an xml file Message-ID: <4D62A135.1040508@nmsu.edu> Hi, I was wondering if someone had some advice: I want to create a set of xml input files to my code that look as follows: Alg1 ./Alg1.in c:\tmp 1 So there are comments, whitespace etc ... in it. I would like to be able to put everything into some sort of structure such that i can access it as: structure['Algorithm']['Type'] == Alg1 I was wondering if there is something out there that does this. I found and tried a few things: 1) http://code.activestate.com/recipes/534109-xml-to-python-data-structure/ It simply doesn't work. I get the following error: raise exception xml.sax._exceptions.SAXParseException: :1:2: not well-formed (invalid token) But i removed everything from the file except: and i still got the error. Anyway, i looked at ElementTree, but that error out with: xml.parsers.expat.ExpatError: junk after document element: line 19, column 0 Anyway, if anyone can give me advice of point me somewhere i'd greatly appreciate it. thanks matt From stefan_ml at behnel.de Mon Feb 21 12:43:16 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 21 Feb 2011 18:43:16 +0100 Subject: python and parsing an xml file In-Reply-To: <4D62A135.1040508@nmsu.edu> References: <4D62A135.1040508@nmsu.edu> Message-ID: Matt Funk, 21.02.2011 18:30: > I want to create a set of xml input files to my code that look as follows: > > > > > > > > > > Alg1 > > > ./Alg1.in > > > > > > > > > c:\tmp > > > > > > 1 > > That's not XML. XML documents have exactly one root element, i.e. you need an enclosing element around these two tags. > So there are comments, whitespace etc ... in it. > I would like to be able to put everything into some sort of structure Including the comments or without them? Note that ElementTree will ignore comments. > such that i can access it as: > structure['Algorithm']['Type'] == Alg1 Have a look at lxml.objectify. It allows you to write alg_type = root.Algorithm.Type.text and a couple of other niceties. http://lxml.de/objectify.html > I was wondering if there is something out there that does this. > I found and tried a few things: > 1) http://code.activestate.com/recipes/534109-xml-to-python-data-structure/ > It simply doesn't work. I get the following error: > raise exception > xml.sax._exceptions.SAXParseException::1:2: not well-formed > (invalid token) "not well formed" == "not XML". > But i removed everything from the file except: encoding="UTF-8"?> > and i still got the error. That's not XML, either. > Anyway, i looked at ElementTree, but that error out with: > xml.parsers.expat.ExpatError: junk after document element: line 19, column 0 In any case, ElementTree is preferable over a SAX based solution, both for performance and maintainability reasons. Stefan From robin at reportlab.com Mon Feb 21 12:56:30 2011 From: robin at reportlab.com (Robin Becker) Date: Mon, 21 Feb 2011 17:56:30 +0000 Subject: LDFLAGS problem Message-ID: <4D62A74E.4070307@chamonix.reportlab.co.uk> After installing python 2.7.1 on a Freebsd 8.0 system with the normal configure make dance ./configure --prefix=$HOME/PYTHON --enable-unicode=ucs2 make make install I find that when I build extensions PIL, MySQLdb I'm getting errors related to a dangling ${LDFLAGS} eg MySQLdb > running build_ext > building '_mysql' extension > creating build/temp.freebsd-7.0-RELEASE-i386-2.7 > gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/include/mysql -I/home/rptlab/PYTHON/include/python2.7 -c _mysql.c -o build/temp.freebsd-7.0-RELEASE-i386-2.7/_mysql.o -fno-strict-aliasing -pipe > gcc -pthread -shared ${LDFLAGS} build/temp.freebsd-7.0-RELEASE-i386-2.7/_mysql.o -L/usr/local/lib/mysql -lmysqlclient_r -lz -lcrypt -lm -o build/lib.freebsd-7.0-RELEASE-i386-2.7/_mysql.so > gcc: ${LDFLAGS}: No such file or directory > error: command 'gcc' failed with exit status 1 where should I be looking to fix this problem? -- Robin Becker From anikom15 at gmail.com Mon Feb 21 12:59:44 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Mon, 21 Feb 2011 09:59:44 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1298311184.2515.4.camel@localhost.localdomain> On Mon, 2011-02-21 at 01:08 +0000, BartC wrote: > > "WestleyMart?nez" wrote in message > news:mailman.202.1298081685.1189.python-list at python.org... > > > > You have provided me with some well thought out arguments and have > > stimulated my young programmer's mind, but I think we're coming from > > different angles. You seem to come from a more math-minded, idealist > > angle, while I come from a more practical angle. Being a person who has > > had to deal with the ? in my last name > > What purpose does the ? serve in your last name, and how is it different > from i? > > (I'd have guessed it indicated stress, but it looks Spanish and I thought > that syllable was stressed anyway.) > > -- > Bartc > > I don't know. I don't speak Spanish, but to my knowledge it's not a critical diacritic like in some languages. From fabio.pliger at gmail.com Mon Feb 21 13:19:28 2011 From: fabio.pliger at gmail.com (Fabio Pliger) Date: Mon, 21 Feb 2011 10:19:28 -0800 (PST) Subject: Europython 2011 - Call for Papers Message-ID: Europython is coming back around! Europython will be held in Florence, Italy from the 20th to the 25th of june. EuroPython is a conference for the Python programming language community. It is aimed at everyone in the Python community, of all skill levels, both users and programmers. It's one of the largest open source conferences in Europe and last year it include over 100 talks, tutorials, sprints and social events. The Call For Paper is the moment when Europython organizers ask the European community to submit their proposals of the talks that will be given at the conference. If you think you have got an interesting topic to talk about, don't hesitate and send us an abstract following the Call for Paper guidelines suggested on this website. This year, we are introducing 4-hours hands-on trainings during the conference, in addition to the regular tracks. During the submission, make sure to specify whether you are willing to change the talk into a 4-hour training. To compensate for the longer preparation required, speakers that will give a training will be rewarded with a free ticket and possibly also a small fee (crossing our fingers that the budget will allow this). Speakers of regular talks will instead benefit from a reduced conference fee. Europython has been proving year after year to be a conference made by the community and for the community, and that's why this year we are happy to introduce the community-based talk voting. We will elaborate on this later on, so stay tuned! We remind everybody that you can follow the updates on the conference, in addition to this blog, both on the official Facebook page and on the Twitter profile @Europython. Many more info can be found at the conference website: www.europython.eu or at the call for papers page: www.europython.eu/call-for-paper See you soon and...we're waiting for your abstracts! The Europython Team From tjreedy at udel.edu Mon Feb 21 13:22:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 21 Feb 2011 13:22:11 -0500 Subject: python and parsing an xml file In-Reply-To: <4D62A135.1040508@nmsu.edu> References: <4D62A135.1040508@nmsu.edu> Message-ID: On 2/21/2011 12:30 PM, Matt Funk wrote: > Hi, > I was wondering if someone had some advice: > I want to create a set of xml input files to my code that look as follows: Why? ... > So there are comments, whitespace etc ... in it. > I would like to be able to put everything into some sort of structure > such that i can access it as: > structure['Algorithm']['Type'] == Alg1 Unless I have a very good reason otherwise, I would just put everything in nested dicts in a .py file to begin with. Or if I needed cross language portability, a JSON file, which is close to the same thing. -- Terry Jan Reedy From dsegleau at gmail.com Mon Feb 21 13:47:33 2011 From: dsegleau at gmail.com (Dave) Date: Mon, 21 Feb 2011 10:47:33 -0800 (PST) Subject: Which non SQL Database ? In-Reply-To: Message-ID: <10b81481-9422-4e72-ac49-471d9c9cd280@glegroupsg2000goo.googlegroups.com> Interesting thread. It started as a discussion of small footprint, embeddable non-SQL databases and has ranged all over the place. For the original purpose of this thread, it certainly sounds like SQLite fits the bill. It's a great package. If you need SQLite's ease of use and simplicity, but you're looking for multi-threaded concurrent access and replication for High Availability, then I would suggest Berkeley DB. It's completely compatible wit SQLite's SQL API, but provides better concurrency and scalability, as well has HA. If you're looking for a non-SQL solution, Berkeley DB offers several non-SQL APIs, including the original BDB key/value pair API, a Java Collections API and a POJO-style Java API (called the Data Persistence Layer). Disclaimer: I'm one of the product managers for Berkeley DB, so I'm a little biased. :-) But I was amused to see claims that BDB wasn't concurrent (not true) or that there were products which were "BDB-like" (why not use the real thing?) so I thought that I would chime in. Good luck on your search. Regards, Dave From ppearson at nowhere.invalid Mon Feb 21 13:55:42 2011 From: ppearson at nowhere.invalid (Peter Pearson) Date: 21 Feb 2011 18:55:42 GMT Subject: hmac module and key format References: <7aef1abd-397c-4eab-9901-93f8d27b8cb3@q40g2000prh.googlegroups.com> <7xzkpq52zz.fsf@ruckus.brouhaha.com> <8sd6l1Ft7vU1@mid.individual.net> <42f27e22-70c3-45e1-ab74-2dcc791bdbaa@w9g2000prg.googlegroups.com> Message-ID: <8sfqpeFvh0U1@mid.individual.net> On Mon, 21 Feb 2011 02:27:36 -0800 (PST), Stuart Longland wrote: [snip] > Before I worried about that though, I needed to have some kind of > understanding as to how the hmac module was used. "Arbitrary string", > sounds to me like I give it something akin to a passphrase, and that > is hashed(?) to provide the symmetric key for the HMAC. Wikipedia > seems to suggest it depends on the length of the key given, so if I > give it a string that's exactly 160-bits (for HMAC-SHA1) it'll use it > unmodified. Would that be a correct assertion? Yes. I predict that you will be glad you look at RFC 2104, http://www.ietf.org/rfc/rfc2104.txt where you will find HMAC summarized as H(K XOR opad, H(K XOR ipad, text)) Here, opad is a block filled with the byte 0x5C, and ipad is a block filled with the byte 0x36. If the key is no longer than one block (and a block is 64 bytes for SHA and MD5), then K is just the key itself; otherwise, K is a hash of the key. -- To email me, substitute nowhere->spamcop, invalid->net. From pradeepbpin at gmail.com Mon Feb 21 13:59:02 2011 From: pradeepbpin at gmail.com (pradeepbpin) Date: Mon, 21 Feb 2011 10:59:02 -0800 (PST) Subject: Return Values & lambda Message-ID: I have a main program module that invokes an input dialog box via a menu item. Now, the code for drawing and processing the input of dialog box is in another module, say 'dialogs.py'. I connect the menu item to this dialog box by a statement like, manu_item.connect('activate', lambda a: dialogs.open_dilaog()) If this function open_dialog() returns a list of dialog inputs values, how can I access those values in the main module ? From rafe.kettler at gmail.com Mon Feb 21 14:03:03 2011 From: rafe.kettler at gmail.com (Rafe Kettler) Date: Mon, 21 Feb 2011 11:03:03 -0800 (PST) Subject: Python 3.2 and html.escape function References: Message-ID: <8c9ff0f5-534f-4292-a04e-ff79e534cdc3@d2g2000yqn.googlegroups.com> On Feb 20, 8:15?am, Gerald Britton wrote: > I see that Python 3.2 includes a new module -- html -- with a single > function -- escape. ?I would like to know how this function differs > from xml.sax.saxutils.escape and, if there is no difference (or only a > minor one), what the need is for this new module and its lone function > > -- > Gerald Britton I believe that they're trying to organize a new top-level package called html that will, at some point, contain all HTML functionality. It's sort of similar to what they're doing with the concurrent package. From stefan_ml at behnel.de Mon Feb 21 14:03:49 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 21 Feb 2011 20:03:49 +0100 Subject: python and parsing an xml file In-Reply-To: References: <4D62A135.1040508@nmsu.edu> Message-ID: Terry Reedy, 21.02.2011 19:22: > On 2/21/2011 12:30 PM, Matt Funk wrote: >> Hi, >> I was wondering if someone had some advice: >> I want to create a set of xml input files to my code that look as follows: > > Why? > > ... >> So there are comments, whitespace etc ... in it. >> I would like to be able to put everything into some sort of structure >> such that i can access it as: >> structure['Algorithm']['Type'] == Alg1 > > Unless I have a very good reason otherwise, I would just put everything in > nested dicts in a .py file to begin with. Or if I needed cross language > portability, a JSON file, which is close to the same thing. Hmm, right, good call. There's also the configparser module in the stdlib which may provide a suitable format here. Stefan From benjamin.kaplan at case.edu Mon Feb 21 14:10:36 2011 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 21 Feb 2011 14:10:36 -0500 Subject: Return Values & lambda In-Reply-To: References: Message-ID: On Mon, Feb 21, 2011 at 1:59 PM, pradeepbpin wrote: > I have a main program module that invokes an input dialog box via ?a > menu item. Now, the code for drawing and processing the input of > dialog box is in another module, say 'dialogs.py'. I connect the menu > item to this dialog box by a statement like, > > manu_item.connect('activate', lambda a: dialogs.open_dilaog()) > > If this function open_dialog() returns a list of dialog inputs values, > how can I access those values in the main module ? You can't. The event handler just calls a method. It's expected that you'll do everything you need in that. Make your own method for the menu item that starts off by creating the dialog and then handles the results. > -- > http://mail.python.org/mailman/listinfo/python-list > From rantingrick at gmail.com Mon Feb 21 14:28:44 2011 From: rantingrick at gmail.com (rantingrick) Date: Mon, 21 Feb 2011 11:28:44 -0800 (PST) Subject: Problems of Symbol Congestion in Computer Languages References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com><9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com><4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Feb 20, 7:08?pm, "BartC" wrote: > "WestleyMart?nez" wrote in message > > news:mailman.202.1298081685.1189.python-list at python.org... > > > You have provided me with some well thought out arguments and have > > stimulated my young programmer's mind, but I think we're coming from > > different angles. You seem to come from a more math-minded, idealist > > angle, while I come from a more practical angle. Being a person who has > > had to deal with the ? in my last name > > What purpose does the ? serve in your last name, and how is it different > from i? Simple, it does not have a purpose. Well, that is, except to give the *impression* that a few pseudo intellectuals have a reason to keep their worthless tenure at universities world wide. It's window dressing, and nothing more. > (I'd have guessed it indicated stress, but it looks Spanish and I thought > that syllable was stressed anyway.) The ascii char "i" would suffice. However some languages fell it necessary to create an ongoing tutorial of the language. Sure French and Latin can sound "pretty", however if all you seek is "pretty music" then listen to music. Language should be for communication and nothing more. From mafunk at nmsu.edu Mon Feb 21 17:07:52 2011 From: mafunk at nmsu.edu (Matt Funk) Date: Mon, 21 Feb 2011 15:07:52 -0700 Subject: python and parsing an xml file In-Reply-To: References: <4D62A135.1040508@nmsu.edu> Message-ID: <4D62E238.5060006@nmsu.edu> HI Stefan, thank you for your advice. I am running into an issue though (which is likely a newbie problem): My xml file looks like (which i got from the internet): Gambardella, Matthew XML Developer's Guide Computer 44.95 2000-10-01 An in-depth look at creating applications with XML. Then i try to access it as: from lxml import etree from lxml import objectify inputfile="../input/books.xml" parser = etree.XMLParser(ns_clean=True) parser = etree.XMLParser(remove_comments=True) root = objectify.parse(inputfile,parser) I try to access elements by (for example): print root.catalog.book.author.text But it errors out with: AttributeError: 'lxml.etree._ElementTree' object has no attribute 'catalog' So i guess i don't understand why this is. Also, how can i print all the attributes of the root for examples or obtain keys? I really appreciate your help thanks matt On 2/21/2011 10:43 AM, Stefan Behnel wrote: > Matt Funk, 21.02.2011 18:30: >> I want to create a set of xml input files to my code that look as >> follows: >> >> >> >> >> >> >> >> >> >> Alg1 >> >> >> ./Alg1.in >> >> >> >> >> >> >> >> >> c:\tmp >> >> >> >> >> >> 1 >> >> > > That's not XML. XML documents have exactly one root element, i.e. you > need an enclosing element around these two tags. > > >> So there are comments, whitespace etc ... in it. >> I would like to be able to put everything into some sort of structure > > Including the comments or without them? Note that ElementTree will > ignore comments. > > >> such that i can access it as: >> structure['Algorithm']['Type'] == Alg1 > > Have a look at lxml.objectify. It allows you to write > > alg_type = root.Algorithm.Type.text > > and a couple of other niceties. > > http://lxml.de/objectify.html > > >> I was wondering if there is something out there that does this. >> I found and tried a few things: >> 1) >> http://code.activestate.com/recipes/534109-xml-to-python-data-structure/ >> It simply doesn't work. I get the following error: >> raise exception >> xml.sax._exceptions.SAXParseException::1:2: not well-formed >> (invalid token) > > "not well formed" == "not XML". > > >> But i removed everything from the file except:> encoding="UTF-8"?> >> and i still got the error. > > That's not XML, either. > > >> Anyway, i looked at ElementTree, but that error out with: >> xml.parsers.expat.ExpatError: junk after document element: line 19, >> column 0 > > In any case, ElementTree is preferable over a SAX based solution, both > for performance and maintainability reasons. > > Stefan > From mafunk at nmsu.edu Mon Feb 21 17:08:07 2011 From: mafunk at nmsu.edu (Matt Funk) Date: Mon, 21 Feb 2011 15:08:07 -0700 Subject: python and parsing an xml file In-Reply-To: References: <4D62A135.1040508@nmsu.edu> Message-ID: <4D62E247.9050303@nmsu.edu> Hi Terry, On 2/21/2011 11:22 AM, Terry Reedy wrote: > On 2/21/2011 12:30 PM, Matt Funk wrote: >> Hi, >> I was wondering if someone had some advice: >> I want to create a set of xml input files to my code that look as >> follows: > > Why? mmmh. not sure how to answer this question exactly. I guess it's a design decision. I am not saying that it is best one, but it seemed suitable to me. I am certainly open to suggestions. But here are some requirements: 1) My boss needs to be able to read the input and make sense out of it. XML seems fairly self explanatory, at least when you choose suitable names for the properties/tags etc ... 2) I want reproducability of a given run without changes to the code. I.e. all the inputs need to be stored external to the code such that the state of the run is captured from the input files entirely. > > > ... >> So there are comments, whitespace etc ... in it. >> I would like to be able to put everything into some sort of structure >> such that i can access it as: >> structure['Algorithm']['Type'] == Alg1 > > Unless I have a very good reason otherwise, I would just put > everything in nested dicts in a .py file to begin with. That is certainly a possibility and it should work. However, eventually the input files might be written by a webinterface (likely php). Even though what you are suggesting is still possible it just feels a little awkward (i.e. to use php to write a python file). > Or if I needed cross language portability, a JSON file, which is close > to the same thing. > again, i am certainly not infallible and open to suggestions of there is a better solution. thanks matt From stefan_ml at behnel.de Mon Feb 21 17:28:23 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 21 Feb 2011 23:28:23 +0100 Subject: python and parsing an xml file In-Reply-To: <4D62E238.5060006@nmsu.edu> References: <4D62A135.1040508@nmsu.edu> <4D62E238.5060006@nmsu.edu> Message-ID: Matt Funk, 21.02.2011 23:07: > thank you for your advice. > I am running into an issue though (which is likely a newbie problem): > > My xml file looks like (which i got from the internet): > > > > Gambardella, Matthew > XML Developer's Guide > Computer > 44.95 > 2000-10-01 > An in-depth look at creating applications > with XML. > > > > Then i try to access it as: > > from lxml import etree > from lxml import objectify > > inputfile="../input/books.xml" > parser = etree.XMLParser(ns_clean=True) > parser = etree.XMLParser(remove_comments=True) Change that to parser = objectify.makeparser(ns_clean=True, remove_comments=True) > root = objectify.parse(inputfile,parser) Change that to root = objectify.parse(inputfile,parser).getroot() Stefan From kvnsmnsn at hotmail.com Mon Feb 21 17:30:26 2011 From: kvnsmnsn at hotmail.com (KevinSimonson) Date: Mon, 21 Feb 2011 14:30:26 -0800 (PST) Subject: Python Tutorial on Multithreading Message-ID: <9fb08df3-d0ed-4aae-ba0e-a27ce62b301d@d23g2000prj.googlegroups.com> I've been teaching myself Python from the tutorial routed at "http:// www.tutorialspoint.com/python/index.htm". It's worked out pretty well, but when I copied its multithreading example from the bottom of the page at "http://www.tutorialspoint.com/python/ python_multithreading.htm" and tried to run it I got the error messages: C:\Users\kvnsmnsn\Python>python mt.py Traceback (most recent call last): File "mt.py", line 38, in thread = myThread(threadID, tName, workQueue) File "mt.py", line 10, in __init__ self.name = name File "C:\Python27\lib\threading.py", line 667, in name assert self.__initialized, "Thread.__init__() not called" AssertionError: Thread.__init__() not called I don't really understand why it's giving me these messages. <__initialized> gets set to when <__init__()> gets called. Granted my Python program calls <__init__()> with only one parameter, and the constructor in "threading.py" takes _seven_ parameters, but all but one have default values, so a call with just one parameter should be legal. Why then is <__initialized> getting set to ? My code follows. Kevin Simonson import Queue import threading import time exitFlag = 0 class myThread (threading.Thread): def __init__(self, threadID, name, q): self.threadID = threadID self.name = name self.q = q threading.Thread.__init__(self) def run(self): print "Starting " + self.name process_data(self.name, self.q) print "Exiting " + self.name def process_data(threadName, q): while not exitFlag: queueLock.acquire() if not workQueue.empty(): data = q.get() queueLock.release() print "%s processing %s" % (threadName, data) else: queueLock.release() time.sleep(1) threadList = ["Thread-1", "Thread-2", "Thread-3"] nameList = ["One", "Two", "Three", "Four", "Five"] queueLock = threading.Lock() workQueue = Queue.Queue(10) threads = [] threadID = 1 # Create new threads for tName in threadList: thread = myThread(threadID, tName, workQueue) thread.start() threads.append(thread) threadID += 1 # Fill the queue queueLock.acquire() for word in nameList: workQueue.put(word) queueLock.release() # Wait for queue to empty while not workQueue.empty(): pass # Notify threads it's time to exit exitFlag = 1 # Wait for all threads to complete for t in threads: t.join() print "Exiting Main Thread" From philip at semanchuk.com Mon Feb 21 17:36:46 2011 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 21 Feb 2011 17:36:46 -0500 Subject: LDFLAGS problem In-Reply-To: <4D62A74E.4070307@chamonix.reportlab.co.uk> References: <4D62A74E.4070307@chamonix.reportlab.co.uk> Message-ID: <5A0474B4-68F6-4EED-8949-15D25D95E9F9@semanchuk.com> On Feb 21, 2011, at 12:56 PM, Robin Becker wrote: > After installing python 2.7.1 on a Freebsd 8.0 system with the normal configure make dance > > ./configure --prefix=$HOME/PYTHON --enable-unicode=ucs2 > make > make install > > I find that when I build extensions PIL, MySQLdb I'm getting errors related to a dangling ${LDFLAGS} > > eg MySQLdb > >> running build_ext >> building '_mysql' extension >> creating build/temp.freebsd-7.0-RELEASE-i386-2.7 >> gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/include/mysql -I/home/rptlab/PYTHON/include/python2.7 -c _mysql.c -o build/temp.freebsd-7.0-RELEASE-i386-2.7/_mysql.o -fno-strict-aliasing -pipe >> gcc -pthread -shared ${LDFLAGS} build/temp.freebsd-7.0-RELEASE-i386-2.7/_mysql.o -L/usr/local/lib/mysql -lmysqlclient_r -lz -lcrypt -lm -o build/lib.freebsd-7.0-RELEASE-i386-2.7/_mysql.so >> gcc: ${LDFLAGS}: No such file or directory >> error: command 'gcc' failed with exit status 1 > > where should I be looking to fix this problem? It's been a while since I built anything on FreeBSD, but one thing that jumps out at me is that you say you're building on 8.0 but the build output you gave us mentions 7.0. That doesn't sound right at all. Are you using ports? bye Philip From mafunk at nmsu.edu Mon Feb 21 17:40:59 2011 From: mafunk at nmsu.edu (Matt Funk) Date: Mon, 21 Feb 2011 15:40:59 -0700 Subject: python and parsing an xml file In-Reply-To: References: <4D62A135.1040508@nmsu.edu> <4D62E238.5060006@nmsu.edu> Message-ID: <4D62E9FB.3080002@nmsu.edu> Hi Stefan, i don't mean to be annoying so sorry if i am. According to your instructions i do: parser = objectify.makeparser(ns_clean=True, remove_comments=True) root = objectify.parse(inputfile,parser).getroot() print root.catalog.book.author.text which still gives the following error: AttributeError: no such child: catalog matt On 2/21/2011 3:28 PM, Stefan Behnel wrote: > Matt Funk, 21.02.2011 23:07: >> thank you for your advice. >> I am running into an issue though (which is likely a newbie problem): >> >> My xml file looks like (which i got from the internet): >> >> >> >> Gambardella, Matthew >> XML Developer's Guide >> Computer >> 44.95 >> 2000-10-01 >> An in-depth look at creating applications >> with XML. >> >> >> >> Then i try to access it as: >> >> from lxml import etree >> from lxml import objectify >> >> inputfile="../input/books.xml" >> parser = etree.XMLParser(ns_clean=True) >> parser = etree.XMLParser(remove_comments=True) > > Change that to > > parser = objectify.makeparser(ns_clean=True, remove_comments=True) > >> root = objectify.parse(inputfile,parser) > > Change that to > > root = objectify.parse(inputfile,parser).getroot() > > Stefan > From stefan-usenet at bytereef.org Mon Feb 21 17:46:34 2011 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Mon, 21 Feb 2011 23:46:34 +0100 Subject: LDFLAGS problem In-Reply-To: <5A0474B4-68F6-4EED-8949-15D25D95E9F9@semanchuk.com> References: <4D62A74E.4070307@chamonix.reportlab.co.uk> <5A0474B4-68F6-4EED-8949-15D25D95E9F9@semanchuk.com> Message-ID: <20110221224634.GA4137@sleipnir.bytereef.org> Philip Semanchuk wrote: > On Feb 21, 2011, at 12:56 PM, Robin Becker wrote: > > After installing python 2.7.1 on a Freebsd 8.0 system with the normal configure make dance > > > > ./configure --prefix=$HOME/PYTHON --enable-unicode=ucs2 > > make > > make install > > > > I find that when I build extensions PIL, MySQLdb I'm getting errors related to a dangling ${LDFLAGS} > > > > eg MySQLdb > > > >> running build_ext > >> building '_mysql' extension > >> creating build/temp.freebsd-7.0-RELEASE-i386-2.7 > >> gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/include/mysql -I/home/rptlab/PYTHON/include/python2.7 -c _mysql.c -o build/temp.freebsd-7.0-RELEASE-i386-2.7/_mysql.o -fno-strict-aliasing -pipe > >> gcc -pthread -shared ${LDFLAGS} build/temp.freebsd-7.0-RELEASE-i386-2.7/_mysql.o -L/usr/local/lib/mysql -lmysqlclient_r -lz -lcrypt -lm -o build/lib.freebsd-7.0-RELEASE-i386-2.7/_mysql.so > >> gcc: ${LDFLAGS}: No such file or directory > >> error: command 'gcc' failed with exit status 1 > > > > where should I be looking to fix this problem? Try the patch from http://bugs.python.org/issue10547 or use an svn checkout. The patch didn't make it into 2.7.1. Stefan Krah From bloring at lbl.gov Mon Feb 21 17:53:12 2011 From: bloring at lbl.gov (Burlen Loring) Date: Mon, 21 Feb 2011 14:53:12 -0800 Subject: python on a cray xt5, ImportError: No module named site Message-ID: <4D62ECD8.2050507@lbl.gov> Hi, Got some trouble running python on a Cray XT5 which has a reduced os on the compute nodes, and you're supposed to link everything statically. I configured the build with --disable-shared and uncommented the modules in Modules/Setup which made sense (nearly all of them), and built with Cray's compiler wrappers. I set PYTHONHOME to point to the install. I am able to run the build fine on the login nodes but when I run on the compute nodes I get the error: "ImportError: No module named site". Full output from -v pasted below. site.py is present. I tried running with -S, and the got "ImportError: No module named os", again os is present. When I commented out the os stuff and ran with -S and just printed sys.path it worked. I'm not sure what the problem is. Can any one shed some light on what's going on here?? Thanks Burlen krakenpf5:/lustre/scratch/bloring$aprun -n 1 python -v ./test.py # installing zipimport hook import zipimport # builtin # installed zipimport hook ImportError: No module named site # clear __builtin__._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.exitfunc # clear sys.exc_type # clear sys.exc_value # clear sys.exc_traceback # clear sys.last_type # clear sys.last_value # clear sys.last_traceback # clear sys.path_hooks # clear sys.path_importer_cache # clear sys.meta_path # clear sys.flags # clear sys.float_info # restore sys.stdin # restore sys.stdout # restore sys.stderr # cleanup __main__ # cleanup[1] zipimport # cleanup[1] signal # cleanup[1] exceptions # cleanup[1] _warnings # cleanup sys # cleanup __builtin__ # cleanup ints: 5 unfreed ints # cleanup floats Application 5091634 exit codes: 1 Application 5091634 resources: utime 0, stime 0 #------------test.py--------------- import sys #import os print sys.path #print "Hello from %d"%(os.getpid()) #------------------------------------ From alex.kapps at web.de Mon Feb 21 18:04:32 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 22 Feb 2011 00:04:32 +0100 Subject: Python Tutorial on Multithreading In-Reply-To: <9fb08df3-d0ed-4aae-ba0e-a27ce62b301d@d23g2000prj.googlegroups.com> References: <9fb08df3-d0ed-4aae-ba0e-a27ce62b301d@d23g2000prj.googlegroups.com> Message-ID: <4D62EF80.9020703@web.de> On 21.02.2011 23:30, KevinSimonson wrote: > I've been teaching myself Python from the tutorial routed at "http:// > www.tutorialspoint.com/python/index.htm". It's worked out pretty > well, but when I copied its multithreading example from the bottom of > the page at "http://www.tutorialspoint.com/python/ > python_multithreading.htm" and tried to run it I got the error > messages: > > C:\Users\kvnsmnsn\Python>python mt.py > Traceback (most recent call last): > File "mt.py", line 38, in > thread = myThread(threadID, tName, workQueue) > File "mt.py", line 10, in __init__ > self.name = name > File "C:\Python27\lib\threading.py", line 667, in name > assert self.__initialized, "Thread.__init__() not called" > AssertionError: Thread.__init__() not called > > I don't really understand why it's giving me these messages. > <__initialized> gets set to when<__init__()> gets called. > Granted my Python program calls<__init__()> with only one parameter, > and the constructor in "threading.py" takes _seven_ parameters, but > all but one have default values, so a call with just one parameter > should be legal. Why then is<__initialized> getting set to? > > My code follows. That tutorial seems to be wrong. According to the official docs: "If the subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread." http://docs.python.org/library/threading.html#thread-objects So, change your __init__ to this: class myThread (threading.Thread): def __init__(self, threadID, name, q): threading.Thread.__init__(self) self.threadID = threadID self.name = name self.q = q HTH From jcea at jcea.es Mon Feb 21 18:27:02 2011 From: jcea at jcea.es (Jesus Cea) Date: Tue, 22 Feb 2011 00:27:02 +0100 Subject: Pickle compatibility between Python 2.7 and python 3.2 Message-ID: <4D62F4C6.4030709@jcea.es> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have 10MB pickled structure generated in Python 2.7. I only use basic types (no clases) like sets, dictionaries, lists, strings, etc. The pickle stores a lot of strings. Some of them should be "bytes", while other should be "unicode". My idea is to import ALL the strings as bytes in Python 3.2 and navigate the data structure to convert the appropiate values to unicode, in a one-time operation (I version the structure, so I can know if this conversion is already done, simply storing a new version value). But I get this error: """ Python 3.2 (r32:88445, Feb 21 2011, 13:34:07) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f=open("file.pickle", mode="rb").read() >>> len(f) 9847316 >>> b=pickle.loads(f,encoding="latin1") Traceback (most recent call last): File "", line 1, in ValueError: operation forbidden on released memoryview object """ I use the encoding "latin1" for transparent byte/unicode conversion (do not touch the values!). This seems to be a bug in Python 3.2. Any suggestion?. PS: The bytestream is protocol 2. - -- Jesus Cea Avion _/_/ _/_/_/ _/_/_/ jcea at jcea.es - http://www.jcea.es/ _/_/ _/_/ _/_/ _/_/ _/_/ jabber / xmpp:jcea at jabber.org _/_/ _/_/ _/_/_/_/_/ . _/_/ _/_/ _/_/ _/_/ _/_/ "Things are not so easy" _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "My name is Dump, Core Dump" _/_/_/ _/_/_/ _/_/ _/_/ "El amor es poner tu felicidad en la felicidad de otro" - Leibniz -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQCVAwUBTWL0xplgi5GaxT1NAQL+NwQAmIXK5er0rJysH0KudC05ys8DxGpswsez oEv60rAVMOImF+2ftizNudvB8FaCoQqEDeshJ3oPN/AmnZ2vqlrMLJdO5hjG88pS W39+qEpRz0JNz2RUdLOpXdLqm9aU56KUqq9F0P8nqI02djsSXTYTmmUHZd37GhPt pV1l7+1cpb0= =pjS+ -----END PGP SIGNATURE----- From steve+comp.lang.python at pearwood.info Mon Feb 21 18:33:03 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Feb 2011 23:33:03 GMT Subject: return an object of a different class References: <960d5210-03a8-44ae-88cc-7c3cd6020e67@h40g2000pre.googlegroups.com> Message-ID: <4d62f62f$0$29972$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 Feb 2011 14:23:10 +0100, Jean-Michel Pichavant wrote: > What is not legit, is to return different objects for which the caller > has to test the type to know what attributes he can use. Well, I don't know... I'm of two minds. On the one hand, I find it *really annoying* when this happens: >>> re.search(pattern, text).group() Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'group' The problem is that re.search and re.match return None instead of a match- object when they don't find anything. Perhaps they should return an empty match object? But on the other hand, there is a well known failure mode caused by doing this: # Strip everything after a comment symbol. offset = text.find("#") text = text[:offset] See the bug? If there's no # in the string, it drops the last character. The most insidious part of the bug is that you might not notice, if your strings end with whitespace. If str.find() returned None, at least you would get a nice TypeError as soon as you tried to use it as a integer offset. So, it's not clear to me whether under *these* circumstances it's better to return a completely different type, which cannot possibly be mistaken for success, or a magic value of the same type. (The third alternative is to raise an exception, and the unspeakably awful alternative is to have a single global error flag for the operation which must be checked.) -- Steven From steve+comp.lang.python at pearwood.info Mon Feb 21 18:33:03 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Feb 2011 23:33:03 GMT Subject: return an object of a different class References: <960d5210-03a8-44ae-88cc-7c3cd6020e67@h40g2000pre.googlegroups.com> Message-ID: <4d62f62f$0$29972$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 Feb 2011 14:23:10 +0100, Jean-Michel Pichavant wrote: > What is not legit, is to return different objects for which the caller > has to test the type to know what attributes he can use. Well, I don't know... I'm of two minds. On the one hand, I find it *really annoying* when this happens: >>> re.search(pattern, text).group() Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'group' The problem is that re.search and re.match return None instead of a match- object when they don't find anything. Perhaps they should return an empty match object? But on the other hand, there is a well known failure mode caused by doing this: # Strip everything after a comment symbol. offset = text.find("#") text = text[:offset] See the bug? If there's no # in the string, it drops the last character. The most insidious part of the bug is that you might not notice, if your strings end with whitespace. If str.find() returned None, at least you would get a nice TypeError as soon as you tried to use it as a integer offset. So, it's not clear to me whether under *these* circumstances it's better to return a completely different type, which cannot possibly be mistaken for success, or a magic value of the same type. (The third alternative is to raise an exception, and the unspeakably awful alternative is to have a single global error flag for the operation which must be checked.) -- Steven From anikom15 at gmail.com Mon Feb 21 18:34:56 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Mon, 21 Feb 2011 15:34:56 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1298331296.6199.0.camel@localhost.localdomain> On Mon, 2011-02-21 at 11:28 -0800, rantingrick wrote: > On Feb 20, 7:08 pm, "BartC" wrote: > > "WestleyMart?nez" wrote in message > > > > news:mailman.202.1298081685.1189.python-list at python.org... > > > > > You have provided me with some well thought out arguments and have > > > stimulated my young programmer's mind, but I think we're coming from > > > different angles. You seem to come from a more math-minded, idealist > > > angle, while I come from a more practical angle. Being a person who has > > > had to deal with the ? in my last name > > > > What purpose does the ? serve in your last name, and how is it different > > from i? > > Simple, it does not have a purpose. Well, that is, except to give the > *impression* that a few pseudo intellectuals have a reason to keep > their worthless tenure at universities world wide. It's window > dressing, and nothing more. > > > (I'd have guessed it indicated stress, but it looks Spanish and I thought > > that syllable was stressed anyway.) > > The ascii char "i" would suffice. However some languages fell it > necessary to create an ongoing tutorial of the language. Sure French > and Latin can sound "pretty", however if all you seek is "pretty > music" then listen to music. Language should be for communication and > nothing more. Nicely said; you're absolutely right. From alex.kapps at web.de Mon Feb 21 18:48:36 2011 From: alex.kapps at web.de (Alexander Kapps) Date: Tue, 22 Feb 2011 00:48:36 +0100 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <1298331296.6199.0.camel@localhost.localdomain> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> <1298331296.6199.0.camel@localhost.localdomain> Message-ID: <4D62F9D4.1080501@web.de> On 22.02.2011 00:34, Westley Mart?nez wrote: > On Mon, 2011-02-21 at 11:28 -0800, rantingrick wrote: >> The ascii char "i" would suffice. However some languages fell it >> necessary to create an ongoing tutorial of the language. Sure French >> and Latin can sound "pretty", however if all you seek is "pretty >> music" then listen to music. Language should be for communication and >> nothing more. > Nicely said; you're absolutely right. http://en.wikipedia.org/wiki/Newspeak (Babbling Rick is just an Orwellian Nightmare, try to ignore him) From sigzero at gmail.com Mon Feb 21 18:54:05 2011 From: sigzero at gmail.com (Robert) Date: Mon, 21 Feb 2011 18:54:05 -0500 Subject: Python on OSX Message-ID: Can I install 2.7 and 3.2 side by side? -- Robert From martin at v.loewis.de Mon Feb 21 18:59:49 2011 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 22 Feb 2011 00:59:49 +0100 Subject: Python 3.2 and html.escape function In-Reply-To: <4d6228c4$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <4d611d80$0$29972$c3e8da3$5496439d@news.astraweb.com> <4d6228c4$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4D62FC75.6030608@v.loewis.de> > Well, I just learned something, thank you. I was under the mistaken > impression that adding new functionality after the first alpha release > was not permitted by the Python devs. It's the first beta release after which no new functionality could be added. Regards, Martin From kvnsmnsn at hotmail.com Mon Feb 21 19:02:11 2011 From: kvnsmnsn at hotmail.com (KevinSimonson) Date: Mon, 21 Feb 2011 16:02:11 -0800 (PST) Subject: Python Tutorial on Multithreading References: <9fb08df3-d0ed-4aae-ba0e-a27ce62b301d@d23g2000prj.googlegroups.com> Message-ID: On Feb 21, 4:04?pm, Alexander Kapps wrote: > > That tutorial seems to be wrong. > > According to the official docs: > > "If the subclass overrides the constructor, it must make sure to > invoke the base class constructor (Thread.__init__()) before doing > anything else to the thread." > > http://docs.python.org/library/threading.html#thread-objects > > So, change your __init__ to this: > > class myThread (threading.Thread): > ? ? ?def __init__(self, threadID, name, q): > ? ? ? ? ?threading.Thread.__init__(self) > ? ? ? ? ?self.threadID = threadID > ? ? ? ? ?self.name = name > ? ? ? ? ?self.q = q > Alexander, thanks! Your suggestion fixed my problem. Kevin S From clp2 at rebertia.com Mon Feb 21 19:08:39 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 21 Feb 2011 16:08:39 -0800 Subject: Python on OSX In-Reply-To: References: Message-ID: On Mon, Feb 21, 2011 at 3:54 PM, Robert wrote: > Can I install 2.7 and 3.2 side by side? Yes, of course. Just don't fiddle with the "System Python" (i.e. the copy preinstalled by Apple). You may wish to install your additional Pythons via Fink or MacPorts. Cheers, Chris From anikom15 at gmail.com Mon Feb 21 19:34:48 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Mon, 21 Feb 2011 16:34:48 -0800 Subject: Problems of Symbol Congestion in Computer Languages In-Reply-To: <4D62F9D4.1080501@web.de> References: <0124dbef-4362-4051-a987-40ae3e123de6@b15g2000pra.googlegroups.com> <9f79f89b-c64e-4ee8-9f0b-43fbd73df981@x4g2000prf.googlegroups.com> <4d5f1684$0$29972$c3e8da3$5496439d@news.astraweb.com> <1298331296.6199.0.camel@localhost.localdomain> <4D62F9D4.1080501@web.de> Message-ID: <1298334888.7312.0.camel@localhost.localdomain> On Tue, 2011-02-22 at 00:48 +0100, Alexander Kapps wrote: > On 22.02.2011 00:34, Westley Mart?nez wrote: > > On Mon, 2011-02-21 at 11:28 -0800, rantingrick wrote: > > >> The ascii char "i" would suffice. However some languages fell it > >> necessary to create an ongoing tutorial of the language. Sure French > >> and Latin can sound "pretty", however if all you seek is "pretty > >> music" then listen to music. Language should be for communication and > >> nothing more. > > Nicely said; you're absolutely right. > > http://en.wikipedia.org/wiki/Newspeak > > > (Babbling Rick is just an Orwellian Nightmare, try to ignore him) > I don't quite get what you mean, but I'm just loving the troll. From rafe.kettler at gmail.com Mon Feb 21 19:43:49 2011 From: rafe.kettler at gmail.com (Rafe Kettler) Date: Mon, 21 Feb 2011 16:43:49 -0800 (PST) Subject: Return Values & lambda References: Message-ID: On Feb 21, 1:59?pm, pradeepbpin wrote: > I have a main program module that invokes an input dialog box via ?a > menu item. Now, the code for drawing and processing the input of > dialog box is in another module, say 'dialogs.py'. I connect the menu > item to this dialog box by a statement like, > > manu_item.connect('activate', lambda a: dialogs.open_dilaog()) > > If this function open_dialog() returns a list of dialog inputs values, > how can I access those values in the main module ? Moreover, I don't see why you need a lambda in this case. Why not just pass the function itself? Rafe From python at rcn.com Mon Feb 21 19:53:09 2011 From: python at rcn.com (Raymond Hettinger) Date: Mon, 21 Feb 2011 16:53:09 -0800 (PST) Subject: An amazing one-minute bit of fun at the interactive prompt References: <7237a8fb-ca71-47a1-a65f-03e280705b1e@y26g2000yqd.googlegroups.com> <9bad625b-5478-47d4-842b-5c0cbfa7b5f7@o1g2000yqb.googlegroups.com> Message-ID: <918ad973-9db7-4f74-bd64-a8d220b7fa5d@s28g2000prb.googlegroups.com> On Feb 21, 12:08?am, Mark Dickinson wrote: > On Feb 20, 8:08?am, Raymond Hettinger wrote: > > > [...] > > >>> n * e > > > 3.1415926 > Very neat! ?Is it supposed to be obvious why this gives an > approximation to pi? ?If so, I'll think about it a bit more; ?if not, > do you have any references? Even after reading the proof, I still don't find it to be obvious ;-) http://home.comcast.net/~davejanelle/mandel.pdf Raymond From steve+comp.lang.python at pearwood.info Mon Feb 21 19:59:30 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Feb 2011 00:59:30 GMT Subject: Return Values & lambda References: Message-ID: <4d630a72$0$29972$c3e8da3$5496439d@news.astraweb.com> On Mon, 21 Feb 2011 16:43:49 -0800, Rafe Kettler wrote: > On Feb 21, 1:59?pm, pradeepbpin wrote: >> I have a main program module that invokes an input dialog box via ?a >> menu item. Now, the code for drawing and processing the input of dialog >> box is in another module, say 'dialogs.py'. I connect the menu item to >> this dialog box by a statement like, >> >> manu_item.connect('activate', lambda a: dialogs.open_dilaog()) >> >> If this function open_dialog() returns a list of dialog inputs values, >> how can I access those values in the main module ? > > Moreover, I don't see why you need a lambda in this case. Why not just > pass the function itself? My guess is that the callback function is passed a single argument, and open_dialog doesn't take any arguments, hence the wrapper which just ignores the argument and calls the function. -- Steven From kwa at kuwata-lab.com Mon Feb 21 21:15:22 2011 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Tue, 22 Feb 2011 11:15:22 +0900 Subject: ANN: pyTenjin 1.0.0 - a high-speed and full-featured template engine Message-ID: Hi all, I released pyTenjin 1.0.0. http://pypi.python.org/pypi/Tenjin/ http://www.kuwata-lab.com/tenjin/ This release contains a lot of enhancements and changes. Overview -------- * Very fast: about 10 times faster than Django template engine * Easy to learn: no need to learn template-original language * Full-featured: nestable layout template, partial template, preprocessing, etc. * Lightweight: only 2000 lines of code and very fast to import. * Google App Engine supported Documents --------- * User's Guide http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html * Examples http://www.kuwata-lab.com/tenjin/pytenjin-examples.html * CHANGES http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Install ------- $ sudo easy_install Tenjin Or: $ wget http://pypi.python.org/packages/source/T/Tenjin/Tenjin-1.0.0.tar.gz $ tar xzf Tenjin-1.0.0.tar.gz $ cd Tenjin-1.0.0/ $ sudo python setup.py install Example ------- ## views/example.pyhtml

${title}

${item}
## main.py import tenjin #tenjin.set_template_encoding('utf-8') # optional (default 'utf-8') from tenjin.helpers import * from tenjin.html import * engine = tenjin.Engine(path=['views']) context = {'title': 'Example', 'items': ['Haruhi', 'Mikuru', 'Yuki'] } output = engine.render('example.pyhtml', context) print(output) ## output $ python main.py

Example

Haruhi
Mikuru
Yuki
Enhancements ------------ * (IMPORTANT!!) Performance is improved (about 5 percent). To improve performance, compiled Python code is changed. This means that YOU MUST TOUCH ALL TEMPLATE FILES AND UPDATE TIME STAMPS OF THEM in order to clear cache data before using this release. ## touch all template files to clear cache data $ find . -name '*.pyhtml' | xargs touch ## show compiled python code $ cat ex.pyhtml